4 ms·
> Text outside of tags is acceptable in modern browsers. Please don't. If it's plaintext serve it as such and if it's html serve it and format it as such. > <
by SahAssar 7y ago
> Text outside of tags is acceptable in modern browsers.
Please don't. If it's plaintext serve it as such and if it's html serve it and format it as such.
> <!DOCTYPE html> is required by the HTML spec
Yes, it is and do it. Disregard everything the author wrote after that on this point.
> <html>, <head>, <body> are not required by modern browsers.
Agreed, they should be left behind. This is a valid HTML doc:
<!DOCTYPE html>
<title>test</title>
<p>test doc here</p>
> You don't need to close your tags.
Some tags need closing, some don't. This is documented in the standard. Follow it, don't just freestyle it.
> If you do not define <meta charset="utf-8">, then most browsers will default to ASCII or Windows-1252. So if you are confidently in the ASCII range, skip the declaration.
Please don't. Set the charset in your headers (and it should be utf-8 unless you have a very good reason).
> Using a preformatted block (<pre>) of links
This is just bad. You have a list of links but you don't use the exact element created for creating lists?
- traes 7y ago> Please don't. Set the charset in your headers (and it should be utf-8 unless you have a very good reason). Legitimate question: why? If I'm not planning on using non-ASCII characters, why bother?
- rglullis 7y agoThere is a huge distance between what you are planning to do and what happens when reality shows up.
- dragonwriter 7y ago> Legitimate question: why? If I'm not planning on using non-ASCII characters, why bother? Because not all character sets are ASCII compatible, and you don't know that your user's default is, even though most browsers' defaults if not customized are.
- thristian 7y agoBecause if you don't specify a character set, the browser will be forced to guess, and even with plain ASCII input the guess is not always reliable: https://en.wikipedia.org/wiki/Bush_hid_the_facts https://en.wikipedia.org/wiki/Bush_hid_the_facts
- lazyjones 7y ago> why? If I'm not planning on using non-ASCII characters, why bother? IF you have any user input at all (forms...), you will end up with major headaches.
- tannhaeuser 7y agoI second this. HTML has very specific rules about which start- and end-element tags can be omitted (and will be inferred if omitted) based on HTML's SGML heritage and the formulation of HTML as an SGML vocabulary. My slides explaining a minimal example are at [1] (the TALK button/link), and the full details are at [2] (meanwhile updated for HTML 5.2). [1]: http://sgmljs.net/docs/sgml-html-tutorial.html http://sgmljs.net/docs/sgml-html-tutorial.html [2]: http://sgmljs.net/docs/html5.html http://sgmljs.net/docs/html5.html
- edflsafoiewq 7y ago<html> should be included so you can hang your lang=en (or whatever) off of it.
- SahAssar 7y agoThat doesn't have to be on the html element though, it can be on another element if so desired.
- chrismorgan 7y agoA lang attribute only affects the element it’s applied to, and any descendants. Putting it on the html element is the most robust way of indicating this. I’d rather not write this: <!doctype html> <meta charset="utf-8"> <link lang="en" title="All blog posts feed" rel="alternate" type="application/atom+xml" href="feed.xml"> <title lang="en">Blog posts</title> <body lang="en"> … I’d rather just do it once: <!doctype html> <html lang=en> <meta charset=utf-8> <link title="All blog posts feed" rel=alternate type=application/atom+xml href=feed.xml> <title>Blog posts</title> …
- SahAssar 7y agoAgreed, was just saying it does not have to be on <html> since I did not know that before checking MDN after your comment.
- dpweb 7y agoI’ve written shortcut code like this for at least 20 years. Mostly for fun and to mock up quicker. The article was a fun thing not a style guide. I prob wouldn’t on a major project but only because there’s negligible cost savings. I find the browser arguments (no pun intended) kinda weak. You can test on a couple platforms and have 100% of an internal corporate environment and 99% of the public internet user agents covered. All programming is choices and opportunity cost. We make decisions based on maxing the value/cost equation. It may make sense for me to cover 99% of user agents and say screw the 1% if my cost benefit warrants it.
- mewpmewp2 7y agoI agree on the purpose that I dislike it when people tout golden good practice rules and how you should always follow them no matter what. I like the approach where I follow best practices situationally and what I consider to be least amount of time spent for getting most value. It does not mean I won't follow best practices for critical systems. If anything, this lets me understand better why there is a best practice for something compared to blindly following them no matter what. For instance I might run into issues when I don't follow them for low critical systems.