# Quick Tip: How to Create an Off-Canvas Feedback Form With Pure CSS

In this super-quick tutorial, we’ll walk through the process of creating an off-canvas feedback form. We won’t use any JavaScript to accomplish this, in fact, we’ll build it by taking advantage of the “CSS checkbox hack technique”. Sound interesting?

Here’s what we’ll be building:

Let’s get started!

## 1. Begin With the Page Markup

We’ll start with a checkbox along with its label and a form. Within the form, we’ll put some common form elements.

Keep in mind that the order here matters. First we’ll place the checkbox, then the label, and finally the form.

We’ll associate each form control with its label by setting the id value equal to the label’s for value:

Here’s the page markup:

 1   2   3 
 4 
 5   6   7 
 8 
 9   10   11 
 12 
 13   14   15 
 16 
 17   18 
 19  

## 2. Define Some Basic Styles

Now let’s define a few custom variables to give us our layout scheme plus some reset rules, especially for the form controls:

 1 :root {  2  --white: white;  3  --gradient: linear-gradient(-45deg, #FFA600 0%, #FF5E03 50%);  4  --form: #eeefef;  5  --border-radius: 4px;  6  --form-width: 500px;  7  --form-mob-width: 320px;  8 }  9 10 * {  11  padding: 0;  12  margin: 0;  13  box-sizing: border-box;  14 }  15 16 button,  17 label {  18  cursor: pointer;  19 }  20 21 label {  22  display: block;  23 }  24 25 button,  26 input,  27 textarea {  28  font-family: inherit;  29  font-size: 100%;  30  border: none;  31 }  32 33 textarea {  34  resize: none;  35 } 

## 3. Style the Form Elements

Now onto the mechanics. As a first step, we’ll visually hide the checkbox:

 1 [type="checkbox"] {  2  position: absolute;  3  left: -9999px;  4 } 

Then, we’ll do the following things:

• Set the checkbox’s label and form as fixed positioned elements. Additionally, we’ll position them in the center right corner of the page.
• Display the label’s text in vertical orientation.
• Hide the form off-canvas. By default, we’ll move it by 100% of its width to the right.

The corresponding styles are as follows:

 1 /*CUSTOM VARIABLES HERE*/  2 3 .feedback-label,  4 .form {  5  position: fixed;  6  top: 50%;  7  right: 0;  8  backface-visibility: hidden;  9 }  10 11 .feedback-label {  12  transform-origin: top right;  13  transform: rotate(-90deg) translate(50%, -100%);  14  z-index: 2;  15 }  16 17 .form {  18  width: var(--form-width);  19  max-height: 90vh;  20  transform: translate(100%, -50%);  21  padding: 30px;  22  overflow: auto;  23  background: var(--form);  24  z-index: 1;  25 } 

Next, we’ll add some straightforward styles to the form elements:

 1 /*CUSTOM VARIABLES HERE*/  2 3 .feedback-label,  4 .form input,  5 .form textarea,  6 .form button {  7  border-radius: var(--border-radius);  8 }  9 10 .feedback-label,  11 .form button {  12  background: var(--gradient);  13  color: var(--white);  14 }  15 16 .feedback-label:hover,  17 .form button:hover {  18  filter: hue-rotate(-45deg);  19 }  20 21 .feedback-label {  22  padding: 5px 10px;  23  border-radius: var(--border-radius) var(--border-radius) 0 0;  24 }  25 26 form div:not(:last-child) {  27  margin-bottom: 20px;  28 }  29 30 form div:last-child {  31  text-align: right;  32 }  33 34 .form input,  35 .form textarea {  36  padding: 0 5px;  37  width: 100%;  38 }  39 40 .form button {  41  padding: 10px 20px;  42  width: 50%;  43  max-width: 120px;  44 }  45 46 .form input {  47  height: 40px;  48 }  49 50 .form textarea {  51  height: 220px;  52 } 

### Toggle Form

Each time we click on the checkbox’s label, the form should appear or disappear with a slide animation. To make that happen, we’ll take advantage of the :checked pseudo-class, the subsequent-sibling selector (~), and the adjacent sibling combinator (+).

Here are the required styles:

 1 /*CUSTOM VARIABLES HERE*/  2 3 [type="checkbox"]:checked + .feedback-label {  4  transform: rotate(-90deg) translate(50%, calc((var(--form-width) + 100%) * -1));  5 }  6 7 [type="checkbox"]:focus + .feedback-label {  8  outline: 2px solid rgb(77, 144, 254);  9 }  10 11 [type="checkbox"]:checked ~ .form {  12  transform: translate(0, -50%);  13 }  14 15 .feedback-label,  16 .form {  17  transition: all 0.35s ease-in-out;  18 } 

Let's discuss the first three styles above:

• The first selector looks for .feedback-label elements that immediately follow checked checkboxes. Here, instead of the + selector, we could equally have used the more generic ~ selector. It then smoothly moves those elements right after the form. Notice the Y value of the translate() function which seems a bit chaotic. If you look at a previous rule this is initially -100%. Now it should be -(form width + 100%). To force the calc() function to return a negative value, we’ll multiply the result of the target operation by -1.
• The second selector looks for .feedback-label elements that immediately follow focused checkboxes. Again here, the ~ selector would work as well. It then gives those elements an outline. This is useful for keyboard accessibility. Use the Tab key to move focus to the checkbox (label). Next, press the Spacebar key to toggle the form state.
• The third selector looks for .form elements that follow (even not immediately) checked checkboxes. It then smoothly moves those elements into view by removing the X value of the translate() function

## 4. Going Responsive

As a last (important) detail, we’ll specify a few rules for mobile screens. This doesn’t involve anything really drastic, we’ll just decrease the form width from 500px to 320px.

The responsive styles:

 1 /*CUSTOM VARIABLES HERE*/  2 3 @media screen and (max-width: 600px) {  4  body {  5  font-size: 16px;  6  }  7 8  .form {  9  padding: 15px;  10  width: var(--form-mob-width);  11  }  12 13  form div:not(:last-child) {  14  margin-bottom: 10px;  15  }  16 17  [type="checkbox"]:checked + .feedback-label {  18  transform: rotate(-90deg) translate(50%, calc((var(--form-mob-width) + 100%) * -1));  19  }  20 } 

## Conclusion

That’s it, folks! Without putting too much effort into this, we managed to implement a useful off-canvas feedback form. I hope you enjoyed this exercise and learned some new things which you can put into practice in the near future.

Let’s look again at what we built: