Overview
HTML = HyperText Markup Language
- The standard markup language for describing the structure of documents displayed on the web
- HTML layer is the content layer of the web
- HTML documents are basically a tree of nodes that make up the DOM.
- HTML boilerplate
- DOM (Document Object Model)
- The HTML itself represents the initial page content, and the DOM represents the updated page content which was changed by the JavaScript code you wrote
- Itās important to mark up your HTML in a way that scripts can easily parse & assistive technologies can understand
Terminology
Element (the entire thing)
<h1>Hello World</h2>ā containers for content, often delineated by tagsHello Worldis the content
- Each HTML element provide the semantics and formatting for documents (creating paragraphs, lists, etc)
- Each element may have multiple attributes specified
- The semantics, or
roleof an element is important to assistive technologies (and some cases, search engines)- Use the
alttext attribute on images!- Donāt include āimage ofā
- Be concise (<125 chars)
- Describe it āover the phoneā
- Use the
- Types
- Non-replaced
- Replaced and void
- Replaced elements - replaced by objects
<input>, <img>, etc
- void - All self-closing elements, represented by one tag
- Replaced elements - replaced by objects
Tags
<h1></h1>- opening tag and the closing tag
- Opening tag always starts with the element type
- browsers donāt display tags, but are used to interpret the content of the page
- not closing tags can range from not displaying as you intended to making the site unusable
- https://developer.mozilla.org/en-US/docs/Web/HTML/Element
Attributes
- Adds additional information to the HTML element (name/value pairs mostly)
- for boolean attributes, you can just put the name
- Only added in the opening tag
- Some attributes are global, some only applies to several elements, some are specific
Void elements (self closing tags)
- cannot contain text content or nested elements
<hr>, <hr/>- Horizontal Rule Element
<br>, <br/>- Break element
- Can add inside
<p>tags - Usually just divide with
<p>tags, and use<br/>only when you have to
<img>, <img/><input><link>, etc.- Add
/for good practice
Text
Landmarks?
- A way to label the major regions of a webpage so that users with screen readers can understand the pageās layout and jump directly to a specific section (like signposts on a website)
- They should be used meaningfully for major sections of your page to create a useful table of contents, but not for every single
<div>, as that would create too much noise.
- They should be used meaningfully for major sections of your page to create a useful table of contents, but not for every single
- Common landmarks include the header, navigation menu, main content area, and footer
<section id="about" aria-labelledby="about_heading">
<h2 id="about_heading">What you'll learn</h2>
...
</section><h2 id="about_heading">: You give your heading a unique ID, in this case,about_heading.<section aria-labelledby="about_heading">: You use thearia-labelledbyattribute on the<section>tag. This attribute tells assistive technologies, āHey, the name for this entire section can be found in the element with the IDabout_heading.ā
Headings
<h1>...<h6>- Donāt nest them, but create a logical heading structure.
- Use these to make your content make sense to search engines, screen readers, and future maintainers (which just might well be you)
- Good practices
Others
<strong></strong>- bold
<em></em>- italic
<!-- I am an html comment -->- comments
Paragraph tags (p tags)
- Automatically breaks for you
- Donāt use empty p tags to add space, but add margin
Button + Input
<button></button><button>Sign up!</button>
- input tag
<input type="text" placeholder="hello">- self closing tag
- need to specify
type- text
- password
- date
- time
- color
- file
- Can add placeholder Example:
Ā Ā Ā
<input type="text" placeholder="Input text">
<input type="password" placeholder="Password" />
<input
type="file"
id="avatar"
name="avatar"
accept="image/png, image/jpeg"
/>
<button>Sign up!</button>
Span
- usually in the middle of another element (theyāre inline)
<div>
<h1>Click <span class="underline">here</span> to get your prize!!</h1>
</div>- has a different value for the display property
- Look: CSS Display and sizing
List
- Types of list
<ul></ul>: Unordered list<ol></ol>:Ordered list- Put
<li></li>inside
- You can nest lists inside lists
- Attributes for lists: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/ol
- start
- rev
- Make sure to put the ending tag after the nested list
<li>B3
<ol>
<li>B31</li>
<li>B32</li>
</ol>
</li>File paths
../- Goes up a level
./dog.png- Stay in current directory
dog.pngalso works (sometimesā¦not recommended lol)
Anchor
<!--Anchor tags-->
<a target="_blank" href="https://www.wikipedia.org" rel="noopener noreferrer">
Wikipedia (opens in new tab)
</a>Class
- used to assign one or more class names to an HTML element
<style>
.highlight {
background-color: yellow;
}
</style>
<div class="highlight">This is highlighted</div>
// Assigning multiple class names
<div class="box shadow"></div>
Id
- TheĀ
idĀ global attributeĀ defines an identifier (ID) that must be unique within the entire document - CSS Selectors & Properties - ID selector
<p id="exciting">The most exciting paragraph on the page. One of a kind!</p>Select
- creates a dropdown, each item in the list is represented by an
<option>and the user can choose one
<select>
<option value="apple">Apple</option>
<option value="banana">Banana</option>
</select>- If user selects Apple, then
valueof<select>will be Apple
Form
<form>
<label for="username">Username:</label>
<input type="text" id="username" name="username">
</form>- The
<label>elementforattribute - links it to an input element- the value must match the
idof the input element it labels
- the value must match the
- The
<input>element- a text field where the user can enter data
- The
id="username"connects it to the label.