{"id":2610,"date":"2020-10-26T04:05:23","date_gmt":"2020-10-26T09:05:23","guid":{"rendered":"https:\/\/cssnewbie.com\/?p=2610"},"modified":"2020-10-26T04:05:23","modified_gmt":"2020-10-26T09:05:23","slug":"how-to-add-forms-in-css","status":"publish","type":"post","link":"https:\/\/cssdeck.com\/blog\/how-to-add-forms-in-css\/","title":{"rendered":"How To Add Forms In CSS"},"content":{"rendered":"<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-2611 size-large\" src=\"https:\/\/cssnewbie.com\/wp-content\/uploads\/2020\/10\/5272-1024x683.jpg\" alt=\"How To Add Forms In CSS\" width=\"1024\" height=\"683\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>We all have seen wonderfully designed forms on sites which compel us to fill the form without giving a reason to skip. Right? Yes, and that is the achievement of the coder and the sales team to get one more user, subscriber or lead.<\/p>\n<p><a href=\"https:\/\/usabilla.com\/blog\/web-forms-their-importance-and-how-to-improve-them\/#:~:text=A%20web%20form%20is%20a,to%20the%20company%20e%2Dmail.\">USABilla<\/a> defines webforms as something that is used by customers to reach the business and for businesses to generate leads.<\/p>\n<p>Basically, there are multiple purposes of adding a form to our website. And more often than not it is sales, but the coder has a vital role to play. <a href=\"https:\/\/wpforms.com\/8-reasons-why-you-need-a-contact-form\/\">WPForms<\/a> lists out some very important reasons you might need a form for your website.<\/p>\n<p>We will learn how to add forms and later how to decorate it to lure the visitor to fill in. Let\u2019s check the basic code for adding a simple form.<\/p>\n<pre>&lt;html&gt;\n&lt;head&gt;\n&lt;title&gt; How to add forms using CSS &lt;\/title&gt;\n&lt;\/head&gt;\n&lt;body&gt;\n&lt;p&gt; Type 1:- Full width &lt;\/p&gt;\n\n&lt;form&gt;\n&lt;label for=\"hola\"&gt; First Name &lt;\/label&gt;\n&lt;input type=\"text\" id=\"fname\" name=\"fname\"&gt;\n&lt;\/form&gt;\n\n&lt;p&gt; Type 2:- Half width &lt;\/p&gt;\n\n&lt;form id=\"check\"&gt;\n&lt;label for=\"hola\"&gt; First Name &lt;\/label&gt;\n&lt;input type=\"text\" id=\"fname\" name=\"fname\"&gt;\n&lt;\/form&gt;\n\n&lt;\/body&gt;\n\n&lt;\/html&gt;<\/pre>\n<p>CSS File:<\/p>\n<pre>input {\n  width: 100%;\n}\n\n#check {\n  width:50%;\n}<\/pre>\n<p>Here&#8217;s how the output will be:<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-2612 size-large\" src=\"https:\/\/cssdeck.com\/blog\/wp-content\/uploads\/2020\/10\/Basicform-1024x267.png\" alt=\"How To Add Forms In CSS\" width=\"1024\" height=\"267\" \/><\/p>\n<p>In the above code we have used &lt;label&gt; and \u00a0&lt;input&gt; as nested tags inside &lt;form&gt; and every time we use the tag &lt;form&gt; it adds a field for collecting data. The attributes used in the &lt;input&gt; tag, <em>type <\/em>can have different values like text, number, password, etc.<\/p>\n<p>The asterisk sign which you see while filling on any website comes on because the type of the input text would have been set to \u201cpassword\u201d. We have used text here.<\/p>\n<p>The <em>id <\/em>property used in the &lt;input&gt; tag is useful when using a PHP file to take action and also to store the data.<\/p>\n<p>The property used in the CSS file is <em>width<\/em> which helps us to set the size of the field to enter the data. We have used 100% &amp; 50% to show how it varies in the final image.<\/p>\n<p>Also, understand how we have called these tags in the CSS file. #check specifically orders the form with id=check and overrides the input method. If we remove the id of the form and delete the #check, both forms will be of full width as written inside the input{}.<\/p>\n<h3>Different Fields<\/h3>\n<p>Let\u2019s learn some different fields by adding borders around the box, background color, or small icons in the field. In the following code, we have used three different fields.<\/p>\n<p>The first one is with a green border with a 2px line around and it is called without using any id. The other two input tags have been assigned an attribute <em>id<\/em> \u2018name\u2019 &amp; \u2018check\u2019. These are used to call in the CSS code to give a red background color and to add attribute <em>value. <\/em><\/p>\n<p>The attribute value used here is CSSNewbies which will be displayed in the field by default over the background color green. So, let\u2019s see the code below:<\/p>\n<pre>&lt;html&gt;\n&lt;head&gt;\n  &lt;title&gt; How to add forms in HTML &lt;\/title&gt;\n&lt;\/head&gt;\n\n&lt;body&gt;\n&lt;p&gt; Different fields &lt;\/p&gt;\n &lt;form&gt;\n  &lt;label for=\"fname\"&gt; Name 1 &lt;\/label&gt;\n  &lt;input type=\"text\" id=\"fname\" name=\"fname\"&gt;\n &lt;\/form&gt;\n\n &lt;form&gt;\n &lt;label for=\"fname\"&gt; Name 2 &lt;\/label&gt;\n &lt;input type=\"text\" id=\"name\" name=\"fname\" value=\"CSSNewbies\"&gt;\n &lt;\/form&gt;\n\n &lt;form&gt;\n &lt;input type=\"text\" id=\"check\" name=\"search\" placeholder=\"Search..\"&gt;\n &lt;\/form&gt;\n\n&lt;\/body&gt;\n&lt;\/html&gt;<\/pre>\n<p>CSS File:-<\/p>\n<pre>input[type=text] {\nwidth: 80%;\npadding: 12px 20px;\nmargin: 6px 0;\nbox-sizing: border-box;\nborder: 2px solid green;\nborder-radius: 4px;\n}\n\n#name {\nwidth: 60%;\npadding: 14px 20px;\nmargin: 10px 0;\nbox-sizing: border-box;\nbackground-color: red;\ncolor: white;\n}\n\n#check{\nwidth: 100%;\nbox-sizing: border-box;\nborder: 2px solid grey;\nfont-size: 20px;\nbackground-color: white;\nbackground-position: 10px 10px;\npadding: 14px 18px 14px 30px;\n}<\/pre>\n<p>Here&#8217;s the output for the above code:<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-2613 size-large\" src=\"https:\/\/cssdeck.com\/blog\/wp-content\/uploads\/2020\/10\/DifferentFields-1024x268.png\" alt=\"How To Add Forms In CSS\" width=\"1024\" height=\"268\" \/><\/p>\n<p><strong>Conclusion<\/strong><\/p>\n<p>In this guide, we saw how to add forms in CSS. We learned how to add a simple form and then how to add background color, border, etc. to the form. You can write your own codes to practice different kinds of forms.<\/p>\n<p>To keep learning such amazing CSS codes, subscribe to our <a href=\"http:\/\/www.cssnewbie.com\">blog<\/a>!<\/p>\n<p>To learn how to add CSS Box Model, visit our previous blog!<\/p>\n<div class=\"wp-socializer wpsr-share-icons \" data-lg-action=\"show\" data-sm-action=\"show\" data-sm-width=\"768\" ><h3>Share and Enjoy !<\/h3><div class=\"wpsr-si-inner\"><div class=\"wpsr-counter wpsrc-sz-32px\" style=\"color:#000\"><span class=\"scount\"><span data-wpsrs=\"\" data-wpsrs-svcs=\"facebook,twitter,linkedin,pinterest,print,pdf\">0<\/span><\/span><small class=\"stext\">Shares<\/small><\/div><div class=\"socializer sr-popup sr-32px sr-circle sr-opacity sr-pad sr-count-1 sr-count-1\"><span class=\"sr-facebook\"><a rel=\"nofollow\" href=\"https:\/\/www.facebook.com\/share.php?u=\" target=\"_blank\"  title=\"Share this on Facebook\"  style=\"color: #ffffff\" ><i class=\"fab fa-facebook-f\"><\/i><span class=\"ctext\"><span data-wpsrs=\"\" data-wpsrs-svcs=\"facebook\">0<\/span><\/span><\/a><\/span>\n<span class=\"sr-twitter\"><a rel=\"nofollow\" href=\"https:\/\/twitter.com\/intent\/tweet?text=%20-%20%20\" target=\"_blank\"  title=\"Tweet this !\"  style=\"color: #ffffff\" ><i class=\"fab fa-twitter\"><\/i><\/a><\/span>\n<span class=\"sr-linkedin\"><a rel=\"nofollow\" href=\"https:\/\/www.linkedin.com\/sharing\/share-offsite\/?url=\" target=\"_blank\"  title=\"Add this to LinkedIn\"  style=\"color: #ffffff\" ><i class=\"fab fa-linkedin-in\"><\/i><\/a><\/span>\n<span class=\"sr-pinterest\"><a rel=\"nofollow\" href=\"https:\/\/www.pinterest.com\/pin\/create\/button\/?url=&amp;media=&amp;description=\" target=\"_blank\"  title=\"Submit this to Pinterest\"  style=\"color: #ffffff\" data-pin-custom=\"true\"><i class=\"fab fa-pinterest\"><\/i><span class=\"ctext\"><span data-wpsrs=\"\" data-wpsrs-svcs=\"pinterest\">0<\/span><\/span><\/a><\/span>\n<span class=\"sr-print\"><a rel=\"nofollow\" href=\"https:\/\/www.printfriendly.com\/print?url=\" target=\"_blank\"  title=\"Print this article \"  style=\"color: #ffffff\" ><i class=\"fa fa-print\"><\/i><\/a><\/span>\n<span class=\"sr-pdf\"><a rel=\"nofollow\" href=\"https:\/\/www.printfriendly.com\/print?url=\" target=\"_blank\"  title=\"Convert to PDF\"  style=\"color: #ffffff\" ><i class=\"fa fa-file-pdf\"><\/i><\/a><\/span><\/div><\/div><\/div>","protected":false},"excerpt":{"rendered":"<\/p>\n<p>&nbsp;<\/p>\n<p>We all have seen wonderfully designed forms on sites which compel us to fill the form without giving a reason to skip. Right? Yes, and that is the achievement of the coder and the sales team to get one more [&#8230;]<\/p>\n<p><a class=\"more-link article\" href=\"https:\/\/cssdeck.com\/blog\/how-to-add-forms-in-css\/\" title=\"Click to read 'How To Add Forms In CSS'\">Read Article<\/a><\/p>\n","protected":false},"author":18,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[168],"tags":[],"_links":{"self":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/2610"}],"collection":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/users\/18"}],"replies":[{"embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/comments?post=2610"}],"version-history":[{"count":0,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/2610\/revisions"}],"wp:attachment":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/media?parent=2610"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/categories?post=2610"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/tags?post=2610"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}