I'm doing some template work on a personal project and I'm trying very hard to keep my lines under 80 characters wide. This is difficult to do with HTML, especially when adding code for dynamic content as well. There are a lot of cases where it would be helpful to put line breaks inside the elements themselves, between attributes. Here's an example:
<a href="http://example.com">foobar</a>
Basically, I want to be able to do this:
<a
href="http://example.com">foobar</a>
without any ill effect. It seems to validate, and Firefox doesn't mind, but I'd like something approaching an authoritative answer. I've tried to find the answer in the HTML specs and Google to no avail.
HTML attributes are generally classified as required attributes, optional attributes, standard attributes, and event attributes: Usually the required and optional attributes modify specific HTML elements. While the standard attributes can be applied to most HTML elements.
To do a line break in HTML, use the <br> tag. Simply place the tag wherever you want to force a line break. Since an HTML line break is an empty element, there's no closing tag.
There are several ways to prevent line breaks in content. Using is one way, and works fine between words, but using it between an empty element and some text does not have a well-defined effect. The same would apply to the more logical and more accessible approach where you use an image for an icon.
This is valid. as far as you don't break the attributes themselves. For example:
These are valid:
<a
href="http://example.com"
>
foobar
<a
href=
"http://example.com"
>
foobar</a>
This is not:
<a href="http://exampl
e.com">foobar</a>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With