HTML Q&A

  • What does DOCTYPE mean? What’s one main result if you do not specify a doctype in an HTML page?

It is an introduction to the web browser about what version of HTML the page is written.
In HTML4, all <!DOCTYPE> declearations require a reference to a Document Type Definition.
Whereas HTML5 does not require that. Without the <!DOCTYPE>, you are forcing the browsers to render in Quirks Mode.


  • What is Metadata in HTML? Why is it useful?

Metadata is used to describe the HTML. Metadata is typically used to specify the page description, keyword, author of the document, viewport, and other information.
Metadata can be used by browsers(how to display content, reload page), search engines(keyword), and other web services.
HTML5 introduced Viewport metadata, which is very useful for page dimensions and scaling. This is useful for high-resolution devices.


  • How do you serve a page with content in multiple languages?

To change the language, just simply set the lang attribute. We can define it anywhere in the document, such as in the body, in the paragraph, in the heading, or in the span tag.
<HTML lang="en">


  • What should you be wary of when designing multilingual sites?
  • use lang attribute in your HTML.
  • Directing users to their native language - Allow users to change their country/language easily without hassle.
  • When translating image text, each string of text will need to have a separate image created for each language.
  • Formatting dates and currencies - Calendar dates are sometimes presented in different ways.
  • Do not concatenate translated strings - Do not do anything like "The date today is " + date. It will break in languages with different word orders. Use a template string with parameters substitution for each language instead.
  • 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.


  • What are data- attributes good for?

data-* attributes allow us to store extra information on standard, semantic HTML elements.
Say you have an article and you want to store some extra information that doesn't have any visual representation.


  • Why is it generally a good idea to position CSS <link>s between <head></head> and JS <script>s just before </body>? Do you know any exceptions?
  • The CSS files are placed in the "head" so that they load and the page is seen as it should be.
  • HTML is loaded line by line. We put the JS file at the bottom of the pages so that the file will be executed after page content is loaded.
  • Currently there is an alternative most recent browsers implemented called async.
    <script src=”main.js” async></script>

By adding the async attribute you are telling the browser to load the file asynchronously. This means it is loaded as a “background task” and will not block the page from continuing to load.


  • How to add CSS?
  • External CSS
    External style are defined within the <link> element, inside the <head> section of an HTML page. With an external style sheet, you can change the look of the entire page by changing just on file.
    <link rel="stylesheet" href="mystyle.css">
  • Internal CSS
    Internal style are defined within the <style> element, inside the <head> section of an HTML page.
    <head>
    <style>
    body {
    background-color: linen;
    }
    h1 {
    color: maroon;
    margin-left: 40px;
    }
    </style>
    </head>
  • Inline CSS
    Inline style are defined within the "style" attribute of the relevent element.
    An inline style may be used to apply a unique style for a single element.
    <h1 style="color:blue;text-align:center;">This is a heading</h1>
    <p style="color:red;">This is a paragraph.</p>


  • Difference between inline elements and block elements. Give some examples.
  • A block element always starts on a new line and takes up the full width available.
    Here are some block-level elements:
    <p>, <div>, <ul>, <ol>, <table>, <h1>
  • An inline element does not start on a new line, it only takes up as much width as necessary.
    Here are some inine-level elements:
    <span>, <image>, <button>, <a>, <li>, <ul>


  • List HTML5 new features you uesd.

I used new tags like: header, footer, main, nav.
I also used new input types like email, range, number, date, color, time, and etc.
LocalStorage(web applications can store data locally within the user’s browser.) is also used to store user preference data and logging information. I also applied new geolocation API to ask for user's location.


  • What is SVG? Benefits of using SVG?

SVG stands for scalable vector graphics. It is used to display graphics on the page.
SVG graphics do not lose any quality if they zoom or resize. Every element and every attribute in SVG files can be animated.


  • local storage vs session storage vs cookie

local storage and session storage are both APIs introduced in HTML5 to save website data.

  • local storage stores data with no expiration date, and gets cleared only through Javascript, or clearing the Browser's cache.
  • Session storage is similar to local storage, but data expires when the browser closed.
  • Cookie stores data that has to be sent back to the server with subsequent requests. Its expiration varies based on the type, and the expiration duration can be set either on the server-side or client-side.


  • Have you used web worker? How did you use it?

Web worker is introduced in HTML5 to execute Javascript in the background. I uesd web worker to prefetch data from API for later use.


  • Tell something about <iframe>. How did you use it and what does it bring?

An inline frame is used to embed another document within the current HTML document. I used <iframe> to include an application developed by another team.
Since iframe loads entire HTML and creates new document, it brings both javascript and CSS encapsulation.

  • Syntax: <iframe src = "URL"></iframe>.


  • Which element should I use to display quoted text?

We can use <backquote>


  • How to upload files to website using HTML?

We can use <input type="file">to upload files.


  • Describe the difference between <script>, <script async> and <script defer>.
  • Async and defer are basically two boolean attributes for the <script> tag. Async allows the execution of scripts asynchronously as soon as they're downloaded. Defer allows execution only after the whole document has been parsed.
  • Both attributes don’t have any effect on inline scripts.


  • What are Semantic Elements?

A semantic element describe its meaning to both browser and developer. It's more friendly to search engine other than using div/span. And it's also good for accessibility.

  • non-semantic element: <div>, <span>
  • semantic element: <form>, <table>, <article>, <header>, <footer>, <aside>


  • Which attribute should we set on <a> in order to open the link in a new tab/window?

target = "_blank"


  • What is singleton tag in HTML?

A singleton tag is also called self-closing tag, which doesn't need a closing tag to be valid.

<br/>
<hr/>
<img/>
<input/>
<link/>
<col/>


  • What is the difference between HTML Tag and HTML Element?

An element is a set of opening and closing tags in use. For example <h1>Some Text</h1>, or <input/>
HTML Tags are like <h1>, <p>


  • What is the difference between <pre></pre> and <p></p>?

The <pre> tag defines preformatted text. The text inside a <pre> element is displayed in a fixed-width font, and it preserves both spaces and breaks.
The <p> tags won't revere spaces and breaks.


  • What is the difference between src and href?

The href attribute specifies the location (URL) of a resource, that an anchor element points to, or the location of a linked resource, like a stylesheet. While the src attribute is used to embed a resource - usually URLs - into a document, think embedded images (<img>) and <script> tags.


  • What is a URL fragment?

Any URL with a hash symbol (#) is a fragment URL. A fragment is usually the right portion of the # symbol. It is an internal page reference, sometimes called a named anchor.
In HTML documents, the browser looks for an anchor tag <a> with an id attribute matching the fragment, and scroll the page to display that section.
Changing the URL fragment will not reload the page.


  • 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.


  • What is progressive rendering?

Progressive Rendering is the technique of sequentially rendering portions of a webpage in the server and streaming it to the client in parts without waiting for the whole page to render.


  • What is an XSS attack?

XSS(cross-site scripting) attacks occur when an attacker uses a web application to send malicious code, generally in the form of a browser-side script, to a different end-user. It occurs anywhere a web application uses input from a user, within the output it generates without validating or encoding it.

An attacker can use XSS to send a malicious script to an unsuspecting user. The end user’s browser has no way to know that the script should not be trusted, and will execute the script. Because it thinks the script came from a trusted source.



最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 203,456评论 5 477
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 85,370评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 150,337评论 0 337
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,583评论 1 273
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,596评论 5 365
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,572评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,936评论 3 395
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,595评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,850评论 1 297
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,601评论 2 321
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,685评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,371评论 4 318
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,951评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,934评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,167评论 1 259
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 43,636评论 2 349
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,411评论 2 342