Explain the first 10 lines of Twitter's source code to me
So... how did I do? ;)<p>---<p>&lt;!DOCTYPE html&gt; is a magic string that indicates the document should be parsed as an HTML5 document (possibly avoiding quirks mode too? I don&#x27;t remember what triggers that).<p>&quot;Doctype&quot; comes from the XML concept, and XHTML documents may have a different doctype.<p>&lt;html&gt; is the document&#x27;s root element. It&#x27;s supposed to be there but the browser will create it if you leave it off.<p>ltr means the document direction is left to right. direction here refers to the direction of lines (e.g. in English lines go left to right, in Arabic lines go right to left). There&#x27;s another value that influences writing mode too below the document level, but I forget what it&#x27;s called.<p>Browser implementers and webmasters have to be careful with a non RTL direction; as it changes the scrolling element origin, the browser will have to deal with logical vs physical coordinates, and scrollX may go negative. I believe scrollX was reconciled across the different browsers fairly recently.<p>The meta tags tell you metadata about the document. I believe they&#x27;re supposed to go in the head section, but again the browser will create that for you if you don&#x27;t.<p>lang just tells you the language of the page. I&#x27;m not familiar with what this is used for, but you could imagine a search engine using it for one thing (e.g. Google&#x27;s &quot;display only results in English&quot;).<p>The two letter country code comes from some standard I don&#x27;t remember the name of. Also used in TLDs. Watch out for easy to confuse countries like cn, ca. Some websites like to use the trendy .io TLD, but I heard rumors it wasn&#x27;t run very well.<p>charset=&quot;utf-8&quot; means the document&#x27;s bytes should be treated as unicode. Note that this meta tag should occur in the first 1024 bytes of the document or browsers may not notice it. Without specifying the charset the browser will likely fall back to... I think latin1?<p>Anyway I read once that browsers don&#x27;t get too fancy with the encoding detection on purpose, to avoid people relying on unreliable heuristics.<p>Another interesting point is that Chrome can load utf-8 documents as utf-8 without a metatag if it&#x27;s a file:&#x2F;&#x2F; URL. I guess conceptually this is because local files can&#x27;t specify the encoding in HTTP headers or something?<p>Viewport specifies the responsive sizing behavior. This is described in the CSS Device Adaptation Level 3 spec; but the section on actually parsing this tag is pretty gnarly. If I remember right it was a non-normative section and had a few weird corners that were likely left over from matching browser implementation quirks.<p>Anyway you need the viewport for responsive viewport sizing. 99% of the time you can just copy-paste the usual string and don&#x27;t need to get fancy with custom values or anything. There&#x27;s also a newer way to specify the viewport behavior through CSS (and indeed Chrome basically converts the meta tag to this internally), but it didn&#x27;t really work right last time I tried it.<p>&quot;og:&quot; is from some semantic web standard. I never learned the details, but basically it tells crawlers some basic information about the page&#x27;s contents.<p>For the remaining lines; presumably Safari recognize some custom meta tags to change Apple device theming. The &quot;origin-trial&quot; may refer to Chrome (or Safari?) origin-trials, where webpages can opt into (or sometimes out of) experimental browser behavior.<p>Line 10 is CSS. Presumably there was a &lt;style&gt; tag off the right end of the screenshot on line 9.<p>Interesting point about CSS or JS embedded in HTML:<p>This actually changes the parser&#x27;s language from HTML parsing to CSS or JS parsing on the fly. But with a special rule to look for the end tag and switch back to HTML. This is why you&#x27;ll see people break up the string &quot;&lt;script&#x2F;&gt;&quot; if they have to embed it in JS embedded in HTML.<p>But my favorite is the &lt;plaintext&gt; tag which switches the parser to... plaintext. Unlike CSS or JS there is no special escape-hatch and it&#x27;s just plaintext for the rest of the document.<p>Speaking of embedded languages: SVGs have a title element but it isn&#x27;t the document&#x27;s title element. Poorly written browsers or crawlers could confuse the SVG title with the document title if they don&#x27;t have an understanding of tag namespaces (another relic from XML perhaps?!)