HTML Flashcards
What does a DOCTYPE do?
DOCTYPE is an abbreviation for Document Type. A DOCTYPE is always associated to a DTD - for Document Type Definition.
A DTD defines how documents of a certain type should be structured (i.e. a button can contain a span but not a div), whereas a DOCTYPE declares what DTD a document supposedly respects (i.e. this document respects the HTML DTD).
For webpages, the DOCTYPE declaration is required. It is used to tell user agents what version of the HTML specifications your document respects. Once a user agent has recognized a correct DOCTYPE, it will trigger the no-quirks mode matching this DOCTYPE for reading the document. If a user agent doesn’t recognize a correct DOCTYPE, it will trigger the quirks mode.
The DOCTYPE declaration for the HTML5 standards is .
How do you serve a page with content in multiple languages?
I will assume that it is asking about the most common case, which is how to serve a page with content available in multiple languages, but the content within the page should be displayed only in one consistent language.
When an HTTP request is made to a server, the requesting user agent usually sends information about language preferences, such as in the Accept-Language header. The server can then use this information to return a version of the document in the appropriate language if such an alternative is available. The returned HTML document should also declare the lang attribute in the tag, such as ….
Of course this is useless for letting a search engine know that the same content is available in different languages, and so you must also make use of the hreflang attribute in the . Eg.
In the back end, the HTML markup will contain i18n placeholders and content for the specific language stored in YML or JSON formats. The server then dynamically generates the HTML page with content in that particular language, usually with the help of a back end framework.
What kind of things must you be wary of when designing or developing for multilingual sites?
Use lang attribute in your HTML.
Directing users to their native language - Allow a user to change his country/language easily without hassle.
Text in raster-based images (e.g. png, gif, jpg, etc.), is not a scalable approach - Placing text in an image is still a popular way to get good-looking, non-system fonts to display on any computer. However, to translate image text, each string of text will need to have a separate image created for each language. Anything more than a handful of replacements like this can quickly get out of control.
Restrictive words/sentence length - Some content can be longer when written in another language. Be wary of layout or overflow issues in the design. It’s best to avoid designing where the amount of text would make or break a design. Character counts come into play with things like headlines, labels, and buttons. They are less of an issue with free-flowing text such as body text or comments.
Be mindful of how colors are perceived - Colors are perceived differently across languages and cultures. The design should use color appropriately.
Formatting dates and currencies - Calendar dates are sometimes presented in different ways. Eg. “May 31, 2012” in the U.S. vs. “31 May 2012” in parts of Europe.
Do not concatenate translated strings - Do not do anything like “The date today is “ + date. It will break in languages with different word order. Use a template string with parameters substitution for each language instead. For example, look at the following two sentences in English and Chinese respectively: I will travel on {% date %} and {% date %} 我会出发. Note that the position of the variable is different due to grammar rules of the language.
Language reading direction - In English, we read from left-to-right, top-to-bottom, in traditional Japanese, text is read up-to-down, right-to-left.
Useful-to-have - include the locale in the path (e.g en_US, zh_CN, etc).
What are data- attributes good for?
Before JavaScript frameworks became popular, front end developers used data- attributes to store extra data within the DOM itself, without other hacks such as non-standard attributes, extra properties on the DOM. It is intended to store custom data private to the page or application, for which there are no more appropriate attributes or elements.
These days, using data- attributes is generally not encouraged. One reason is that users can modify the data attribute easily by using inspect element in the browser. The data model is better stored within JavaScript itself and stay updated with the DOM via data binding possibly through a library or a framework.
However, one perfectly valid use of data attributes, is to add a hook for end to end testing frameworks such as Selenium and Capybara without having to create a meaningless classes or ID attributes. The element needs a way to be found by a particular Selenium spec and something like data-selector=’the-thing’ is a valid way to do so without convoluting the semantic markup otherwise.
Consider HTML5 as an open web platform. What are the building blocks of HTML5?
Semantics - Allowing you to describe more precisely what your content is.
Connectivity - Allowing you to communicate with the server in new and innovative ways.
Offline and storage - Allowing webpages to store data on the client-side locally and operate offline more efficiently.
Multimedia - Making video and audio first-class citizens in the Open Web.
2D/3D graphics and effects - Allowing a much more diverse range of presentation options.
Performance and integration - Providing greater speed optimization and better usage of computer hardware.
Device access - Allowing for the usage of various input and output devices.
Styling - Letting authors write more sophisticated themes.
Describe the difference between a cookie, sessionStorage and localStorage
All the above-mentioned technologies are key-value storage mechanisms on the client side. They are only able to store values as strings.
Cookie - Initiator
Client or server. Server can use Set-Cookie header
Cookie - Expiry
Manually set
Cookie - Persistent across browser sessions?
Depends on whether expiration is set
Cookie - Sent to server with every HTTP request?
Cookies are automatically being sent via Cookie header
Cookie - Capacity (per domain)
4kb
Cookie - Accessibility
Any window
localStorage - Initiator
Client
localStorage - Expiry
Forever
localStorage - Persistent across browser sessions?
Yes