10 ms·
HEAD – A guide to <head> elements
- grenoire 7y agoThis is absolutely mortifying, how much metadata do pages have to share with browsers to do that one weirdly specific thing!?
- krapp 7y agoWhat weirdly specific thing? You don't have to put anything in a head tag, you don't even need a head tag, but it's a good idea to have one and to at least add a charset meta tag. Everything is optional, though. The entire point of it is for you to share metadata about your page with the browser.
- munk-a 7y agoMy favorite weird thing that happens without certain <head> tags is the ten billion attempts to get a favicon. I don't know if browsers still try all those silly favicon requests if none is defined, but it was saddening to watch that grow to be wide spread previously.
- shakna 7y agoYes, they all still issue several favicon requests, so far as I'm aware. Having one, instead of returning a 404, can speed up the page load. Which makes 0 sense.
- dyanaraps 7y agoThis is how I avoid this issue entirely: <link href=data:, rel=icon> This is the smallest possible "null" favicon. It causes the browser to display nothing and ensures 0 HTTP requests for the favicon!
- SquareWheel 7y agoDoes the browser display the generic "no favicon" icon, or is it just completely blank? I like the idea.
- dyanaraps 7y agoIt's completely blank (tested in Firefox and Chromium).
- deleted 7y ago[deleted]
- mpolichette 7y agoThis is specifically elements which are allowed in the `head` element of the document. I recently read somewhere that for backwards compatibility reasons no new element types can be added within `head`. This causes a lot of overloading on the existing ones for elements like <link />. I don't have any supporting evidence though.
- giancarlostoro 7y agoI havent heard of that but looking through RFCs might be the way to find out.
- edflsafoiewq 7y agoThe HTML syntax lets you omit the </head> tag. Any start tag not in the finite list of elements will implicitly start the body and go there. <html> <head> <title>I am in the head</title> <foo>I am in the body!</foo> </head> <- this is a parse error and is ignored
- tannhaeuser 7y agoHTML even lets you omit the <html> and <head> tags, so the following is valid and equivalent: <title>I am in the head</title> <foo>I am in the body</foo> I've described how this works for SGML here [1], but it also applies to HTML. [1]: http://sgmljs.net/docs/sgml-html-tutorial.html http://sgmljs.net/docs/sgml-html-tutorial.html (see slides linked from TALK)
- Izkata 7y agoScrew it, let's abandon all markup and content: https://mathiasbynens.be/demo/css-without-html https://mathiasbynens.be/demo/css-without-html (Explanation: https://css-tricks.com/using-css-without-html/ https://css-tricks.com/using-css-without-html/ )
- seph-reed 7y agoImmediately found a bunch of elements I had never heard of. This is really neat.
- The_rationalist 7y agoEspecially <base>
- cj 7y agoI've found this especially useful when rendering proxied web pages
- munk-a 7y ago<base> was super nice in the old days when I worked with servers without subdomains for staging/testing, it made it pretty trivial to have domain.tld/website and domain.tld/testing/website ... granted, those were dark days and I'd never use that approach now, but it was appreciated.
- berkut 7y agoOut of interest, what would you use instead these days?
- munk-a 7y agoOh, usually <base> is still bound to the server root name, but in most cases an SPA or what-have-ye will be served off the base subdomain with client side routing hints - then everything can just be referenced using stripped down relative URLs. Actually though, for the server-side processed stuff we are still using <base> to make sure that /fancy/bespoke/url/style URLs doesn't try to grab assets from /fancy/bespoke/url/style/styles/main.css - I guess it's less that I don't use it and more that now-a-days I rarely set it to anything other than domainname since I'll just materialize a new subdomain if I need to do something fancy.
- WiseWeasel 7y ago
- rolltiide 7y agoDoes anybody remember that funny thread where some dev here was saying "who calls it HTML5 anymore" as if everyone else was out of touch with stagnating irrelevant skills that would immediately throw red flags during a phone screen? It just gave me a chuckle thinking about it Thanks for the guide!
- kizer 7y agoUh... what do people call "it" now-a-days? Serious
- munk-a 7y agoMostly HTML5 in my experience. Less seriously, sometimes it's referred to as "Oh, whatever happened to XHTML 2.0, I was so looking forward to that, oh well guess we're using HTML5" but this is usually at conferences.
- 0x4a42 7y agoMaybe just HTML?
- deleted 7y ago[deleted]
- hombre_fatal 7y agoIt's kinda like how sometimes you use "Javascript" but in some contexts you're talking about a specific version (e.g. new features) and will instead mention it by a version name.
- erik_seaberg 7y agoJavascript thick clients.
- rolltiide 7y ago"web dev" according to that guy from the old thread sure, I've heard that context too
- 7y ago
- liquidise 7y ago> Below are the essential elements for any web document (websites/apps) > "...width=device-width, initial-scale=1..." This is a surprising bit of opinionation to an otherwise decent presentation of head elements. Websites render quite nicely on modern phones without this line, but they generally render as if they are on a desktop browser. Using the above meta tag allows you easy access to modern approaches to mobile development.
- akersten 7y agoI'm not an expert. But in my experience, that line has been the solution to 100% of any viewport issue I've ever had on mobile, and has made webpages "just work" and render how I'd expect them to on mobile, as opposed to weird issues with font size and scrolling. I've never had that line do something I didn't want. Is there a reason mobile browsers don't automatically just do whatever that line does? Seems like the opt-in behavior should be "yes, render me like I'm a desktop site on a tiny monitor" rather than opt-out.
- Brendinooo 7y agoLegacy reasons. When the iPhone came out, "mobile only" sites were a wasteland of terrible UI and restricted features. iPhone OS wanted to serve full websites, and sometimes had to do weird things to beat the kind of stuff that sniffed for mobile devices, or to overcome the lack of a mouse on a desktop website. If you look at the original iPhone demo in 2007[0], the original intent was to render full web pages on the screen and rely on the double-tap-to-zoom to read content. The article that's generally credited with naming and mainstreaming Responsive Web Design[1] didn't come until 2010. [0]: https://youtu.be/vN4U5FqrOdQ?t=2502 https://youtu.be/vN4U5FqrOdQ?t=2502 [1]: https://alistapart.com/article/responsive-web-design/ https://alistapart.com/article/responsive-web-design/
- maccard 7y agoCompletely off topic, but it's hilarious how slow the NY times website loads in that first video.
- 7y ago
- saagarjha 7y ago> The above 2 meta tags must come first in the <head> to consistently ensure proper document rendering. It looks like they don't follow their own advice: <head> <meta charset="utf-8"> <meta http-equiv="x-ua-compatible" content="ie=edge"> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0">
- bcoates 7y agoDo what they say, not what they do! maximum-scale has only three valid uses: 1. extreme values, like 5.0, if a browser misdetects that zooming that far is useful when it isn't (rare) 2. pure-app websites like maps or video games that have alternative scaling arrangements and browser pinch-zoom gets in the way. 3. there is no number three, and the thing you are thinking of is incorrect. maximum-scale is an automatic usability and accessibility fail otherwise, you are bad and should be made to feel bad if you use it.
- kizer 7y agoIf you limit it to 1.0 by default across the board, in particular, you mean, right?
- kizer 7y agoThis is the thing that limit the zoom-out with a pinch in safari/scroll beyond the page and see the "surface" underneath I'm assuming correctly hopefully
- bcoates 7y agoThere's no reason to ever defeat the pinch-in behavior, it's what lets the user know the page is fully zoomed out. maximum-scale=1.0 causes the page to be unscalable on mobile and is almost never what you want.
- jsploit 7y ago> maximum-scale is an automatic usability and accessibility fail I wish more people realized this. As somebody that's visually impaired, it makes mobile browsing quite painful for me.
- kizer 7y agoWe need more single page references like this, IMO, for all sorts of random domains. Even something like a single-page reference for how Array.from works in JS, as an example. Even if it were standalone it could later be integrated into a broader reference work. In the meantime, a "arrayfrom.dev" page, although non-general, would fill a specific niche w/ a mnemonic URL (Array.from is just an example - no idea whether or not it would be considerable in this regard). Other "pages" (as rough-sketch descriptions) I can imagine: colors.dev, cacheperf.dev, unicode.dev, rdf/microdata.dev, parsing.algorithms.dev, querystring.dev (a micro reference for sure). Likewise, "micro" web tools which I'm sure exist as a concept I don't know already would be very convenient (xml->json converter, linters/viewers/auditors of all sorts).
- bcoates 7y agoIs mdn not satisfactory for that? searching 'mdn array.from' brings up a nice one-pager on that and it works for almost any web/js documentation.
- tomp 7y ago<meta name="viewport" content="width=device-width, initial-scale=1"> Please no. IMO this makes most pages unusable on mobile. Most websites, e.g. news websites with long-form articles, shouldn't be using mobile pages / responsive design / zoomed-in layout at all. Web apps (Twitter, GMail), maybe. But most mobile pages are far more unusable than desktop versions (looking at you, Facebook and Reddit).
- nix0n 7y agoIt seems to work well for motherfuckingwebsite.com (their <head> is almost exactly the "recommended minimum" here). But, I also have no problem with Facebook's mobile site, so maybe I just don't see the same problems as you are seeing.
- akersten 7y agoWe must have different devices. IMO most pages are unusable on mobile without this. I wonder if it's the device, website content, or personal preference at play here.
- deleted 7y ago[deleted]
- kalleboo 7y ago> news websites with long-form articles, shouldn't be using mobile pages / responsive design / zoomed-in layout at all Do you mean you actually prefer having to scroll left/right/left/right/left/right when reading a long article?
- tomp 7y agoNo, Safari on iOS auto-formats text columns to be screen width when you zoom in (double-tap) on them... but the rest of the website is intact!
- kalleboo 7y agoIf I double-tap a column of text, it will zoom in on the part of the page to fit the width of the column on the screen, but if the column is too wide (e.g. a page with just a single 100% width column of text) the text size is still unreadably small. It won't reflow the column to fit the screen. (e.g. try visiting http://www.catb.org/~esr/jargon/html/I/ICBM-address.html http://www.catb.org/~esr/jargon/html/I/ICBM-address.html, a page with no viewport directive and not even any page width CSS) The early Android browser used to actually reflow columns to fit on the mobile screen when you zoomed in, but it lost that in the transition to Chrome.
- alexdumitru 7y ago> <!-- Identify the software used to build the document (i.e. - WordPress, Dreamweaver) --> <meta name="generator" content="program"> Is Dreamweaver still a thing? I haven't heard of it in years, many years.
- dfsegoat 7y agoI last touched it in 2012 - but apparently, yes, yes it is: https://helpx.adobe.com/dreamweaver/using/whats-new.html https://helpx.adobe.com/dreamweaver/using/whats-new.html Although, it looks like their cumulative 2019 updates are limited to the following headlines between the two: 1) added support for HTML tag highlighting inside PHP code 2) bootstrap CSS support. ... I was surprised to see it was still alive.
- hnzix 7y agoI use Dreamweaver all the time. It's actually a full-blooded static site generator, two decades before that was trendy. And marketing can use the visual editor to make it a content management system.
- wolco 7y agoI still use a copy because no editor has a built in sftp anymore. Sublime/vs code/phpstorm are great for git projects but for remote projects you don't want to work on locally dreamweaver can't be beat. The only problem is modern code has changed syntax so dreamweaver gives warnings for valid code. I wonder if anyone has updated these.
- walshemj 7y agoBit light on the use of the Hreflang
- combatentropy 7y agoWhy would <meta charset="utf-8"> be required if you can set it in the HTTP headers? I've also read that modern browsers (everything except IE) will look for a byte-order mark.
- tyingq 7y agoProbably nice for people that save the HTML document locally via curl or similar.
- combatentropy 7y agocurl or similar could inject a meta tag. Or we could have a default of UTF-8. I don't dispute that it can be nice. I am just curious why so many say it is required.
- tyingq 7y agoI imagine it's the cumulative amount of my first example, curl, and probably other "save as html" functionality in some browsers, crawlers, s3 buckets, archival tools, and so on. I'm sure many can do as you suggested and inject the header, but suspect many don't. Another use case might be content that is authored in a content management system. Perhaps it's the easiest way to carry your intended charset to the destination.
- gog 7y agoQuite a few of these can be set in the HTTP headers as well, but people editing templates don't always have access or know how to do it. BTW; not all UTF-8 text has a byte-order mark, I would say most of them don't.
- kevin_thibedeau 7y agoBOM is not valid in UTF-8 for one thing.
- 7y ago
- saagarjha 7y agoQuestion: how many of these are standardized? I'm not particularly interested in adding a bunch of specific, proprietary tags…
- jaimex2 7y agoI'd go by W3 https://www.w3schools.com/html/html_head.asp https://www.w3schools.com/html/html_head.asp Then again were all slaves to the whims of Alphabet and Facebooks for traffic.
- duskwuff 7y agoW3Schools is not W3C, and is frequently inaccurate.
- colejohnson66 7y agoRe: them being inaccurate: that was true many moons ago, but it seems they’ve cleaned up and are more accurate now IMHO.
- duskwuff 7y agoThey're less inaccurate than they used to be -- I'll give them that. But I still wouldn't rely on them as a source.
- hatfortguy 7y agoMDN is often a better alternative to W3Schools. They cover a lot of "web" things, not just JS docs.
- lurchpop 7y agoICBM tag with targeting coordinates hmm
- jameshart 7y agoThey link to a helpful explanation: https://en.wikipedia.org/wiki/ICBM_address https://en.wikipedia.org/wiki/ICBM_address tl;dr you should not expect to actually be targeted with an ICBM unless you foolishily also include elevation information.
- zmix 7y agoDublinCore[1] is totally missing! It once was the metadata standard, it's understood by archives and libraries (including Library of Congress) worldwide, macOS will automatically import them into spotlight, etc. Instead we find many of those tags (title, description, author, etc.) hidden behind the namespace of some corporations. [1] https://www.dublincore.org/specifications/ https://www.dublincore.org/specifications/
- 1shooner 7y agoAre these corporate 'namespaces' themselves even a standard? Isn't the prefix in meta@name just an informal convention?
- nodesocket 7y agoSurprised all icons is only: <!-- Icon in the highest resolution we need it for --> <link rel="icon" sizes="192x192" href="/path/to/icon.png"> <!-- Apple Touch Icon (reuse 192px icon.png) --> <link rel="apple-touch-icon" href="/path/to/apple-touch-icon.png"> I thought there was literally like a dozen different sizes and names to support all different Apple and Android devices.
- why-oh-why 7y agoYou don’t even need those. Safari will automatically look for a file on the root and so does Android. Still, I know what you’re talking about and it’s awful how many “gurus” suggest all that noise.
- myfonj 7y agoYes. See this comprehensive resource [0] or sieve trough those linked at the Head project [1] - there are still bunch of tags (especially if you cannot place images into the root path) and myriad of images with varying degree of importance. Even now most resources apparently slightly disagrees with each other. [0] https://realfavicongenerator.net/faq https://realfavicongenerator.net/faq [1] https://htmlhead.dev/#icons https://htmlhead.dev/#icons
- cproctor 7y agoFun fact: there's no way to do logical grouping for head elements. (eg no divs allowed)
- anamexis 7y agoWhy would this be useful? Other than for human legibility, but I feel like that can be accomplished with line breaks and comments.
- jbverschoor 7y agoWhite space ;)
- floatingatoll 7y ago> Completely opt out of DNS prefetching by setting to "off" Why is this included in these guidelines? EDIT: See reply. Thanks!
- ratww 7y agoThat's not a recommendation, the site is just documenting it.
- zawerf 7y agoExpress Helmet also turns it off by default and included a rationale for why (tldr: privacy leaks when there are random external links posted on a page): https://helmetjs.github.io/docs/dns-prefetch-control/ https://helmetjs.github.io/docs/dns-prefetch-control/
- badrabbit 7y agoWould love to see if/how these apply to html email/email-clients.
- coagmano 7y agoEmail clients don't give a shit about your html. They will straight mess you up
- qazqwert 7y agowat.. ok
- perilunar 7y agoThose dark grey on black comments are annoyingly hard to read. Web inspector to the rescue.
- GlitchMr 7y ago"Recommended Minimum" lists <meta name="viewport" content="width=device-width, initial-scale=1">. While it is indeed recommended, the site should say to actually try testing the website on a mobile device with this attribute before adding it - marking the website as mobile friendly when it's not is worse than not doing so.
- Beltiras 7y agoMissed the perfect headline: "A guide to giving head - all of the elements"