Sub topic 2
Inline Text, Lists, and Links
This chapter assumes you can create a basic HTML document and recognize elements, start tags, end tags, and attributes. HTML elements describe the meaning and structure of content. Browsers use that structure to display the page.
Inline text elements
Inline elements stay within the current line of text unless the browser needs to wrap the line. Use elements that describe meaning, rather than styling alone.
<p>
Read the <strong>important</strong> warning and
<em>carefully</em> follow the instructions.
</p><strong> marks strong importance. <em> marks emphasis. Other useful inline elements include <code> for a short code sample and <mark> for highlighted text.
Character references and comments
A character reference represents a character that could be confused with HTML syntax or is difficult to type.
<p>Use <h1> for a main heading. Save 50 MB.</p>
<!-- This note is visible in the source, not on the page. -->< displays <, and inserts a non-breaking space. Comments begin with <!-- and end with -->. Do not put passwords or other secrets in comments because anyone viewing the source can read them.
Block content, inline content, and nesting
Block-level content normally starts on a new line and takes the available width. Paragraphs, headings, and list elements are common block elements. Inline content, such as <a> and <strong>, fits inside surrounding text.
Nest elements according to their content rules, and close them in reverse order:
<p>This is <strong>valid <em>nested</em> text</strong>.</p>The <em> element closes before <strong> because it opened later.
Lists
Use <ul> for an unordered list and <ol> when order matters. Each item must be an <li> element. A description list uses <dl>, with <dt> terms and <dd> descriptions.
<ul>
<li>HTML</li>
<li>CSS</li>
</ul>
<ol>
<li>Write the markup</li>
<li>Open the file</li>
</ol>
<dl>
<dt>HTML</dt>
<dd>The language that structures web content.</dd>
</dl>Links and URLs
An anchor element creates a link. Its href attribute contains the destination.
<p>
Visit <a href="https://developer.mozilla.org/">MDN Web Docs</a>.
</p>An absolute URL includes the complete address. A relative URL points to a resource within the same website, such as href="about.html". Use link text that explains the destination. Avoid vague text such as “click here.”
Exercise
Which element should contain the items in both ordered and unordered lists?
Show answer
Each item must be an <li> element.