Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS styling of form tags

As far as I am aware, a <form></form> tag is supposed to be invisible as part of a webpage, and that when designing a form, one should use div tags (or equivalent) to represent the physical form structure.

Is it acceptable (according to W3C standards) to apply CSS to a <form></form> tag? and can anyone point me in the right direction for literature on this issue?

like image 757
Matthew Layton Avatar asked Jul 23 '12 14:07

Matthew Layton


People also ask

How do I style a form element in CSS?

Styling Input Fields If you only want to style a specific input type, you can use attribute selectors: input[type=text] - will only select text fields. input[type=password] - will only select password fields. input[type=number] - will only select number fields.

Can I style a form tag?

A form is just another element of the page (think of it as a div which can contain input/other elements). You can style it with CSS just like any other element - it's all completely valid. Save this answer.

What is styling forms with CSS?

CSS form is used to create interactive forms for users and provides many ways to set the style. There are many CSS properties available that can be used to create and style HTML forms to make them more interactive.

How do I customize my CSS in Google forms?

Right-click any element in the Google Form and choose Inspect Element . Next, switch to the Styles panel and experiment with different styles for colors, padding, font-size and any other CSS property. You can then copy the CSS and paste it into the custom CSS section.


2 Answers

As far as I am aware, a <form></form> tag is supposed to be invisible as part of a webpage

It is supposed to represent a form. That is definitely visible thing

and that when designing a form, one should use div tags (or equivalent) to represent the physical form structure.

<div> is the tag of last resort. Use it when something more suitable (like <form> or <fieldset>) does not exist.

Is it acceptable (according to W3C standards) to apply CSS to a <form></form> tag?

Baring bugs in browsers, it is acceptable to style any element in the document.

and can anyone point me in the right direction for literature on this issue?

Since there is nothing special about the element, it does not need specific documentation.

The closest I can think of is this warning from the CSS 2.1 specification:

Note. CSS gives so much power to the "class" attribute, that authors could conceivably design their own "document language" based on elements with almost no associated presentation (such as DIV and SPAN in HTML) and assigning style information through the "class" attribute. Authors should avoid this practice since the structural elements of a document language often have recognized and accepted meanings and author-defined classes may not.

… but relating that to the question is a stretch since you are suggesting using semantic markup, but adding unnecessary divs purely for styling.

like image 133
Quentin Avatar answered Oct 21 '22 08:10

Quentin


A form is just another element of the page (think of it as a div which can contain input/other elements). You can style it with CSS just like any other element - it's all completely valid.

like image 4
whostolemyhat Avatar answered Oct 21 '22 09:10

whostolemyhat