HTML Exam 3: Advanced Concepts and Best Practices (20 Challenges)
HTML Exam 3: Advanced
This exam includes 20 challenges focused on advanced concepts and best practices.
Exercises 1-10: Beginner level |
Exercises 11-15: Intermediate level |
Exercises 16-20: Advanced
Add appropriate ARIA attributes:
- You have a `div` styled as a close “X” button.
- Add `role=\"button\"` and `aria-label=\"Close\"`.
- Make it focusable (`tabindex=\"0\"`).
<div role="button" aria-label="Close" tabindex="0">X</div>
Use data attributes:
- Create an `li` for a product with `data-id=\"12345\"`.
- Add `data-price=\"99.99\"`.
- Add `data-category=\"electronics\"`.
<li data-id="12345" data-price="99.99" data-category="electronics">
Smartphone
</li>
Write the correct paths:
- You are in the `pages` folder; display `logo.png` from the same folder.
- Display `bg.jpg` from the `images` folder one level up.
<img src="logo.png" alt="Logo">
<img src="../images/bg.jpg" alt="Background">
Add a favicon:
- Add the code in the head to include `favicon.ico`.
- Use `rel=\"icon\"` and `type=\"image/x-icon\"`.
<link rel="icon" type="image/x-icon" href="/en/favicon.ico">
Link external files:
- Link `style.css` from the `css` folder.
- Link `script.js` from the `js` folder with `defer`.
<link rel="stylesheet" href="css/style.css">
<script src="js/script.js" defer></script>
Use global attributes:
- Make a paragraph editable (`contenteditable`).
- Add a tooltip to a button using `title`.
<p contenteditable="true">You can edit this text!</p>
<button title="Click here for more">Info</button>
Add Open Graph tags:
- `og:title` for the title.
- `og:image` for the preview image.
- `og:description` for the description.
<meta property="og:title" content="My Page Title">
<meta property="og:image" content="https://example.com/image.jpg">
<meta property="og:description" content="Page description">
Display emojis:
- Ensure UTF-8 is used in the head.
- Display a smiling face using an HTML code.
<meta charset="UTF-8">
<p>Hello 😀</p>
Group options in a dropdown:
- Create a `select` for cars.
- Group under “German Cars” and “Japanese Cars”.
<select name="cars">
<optgroup label="German Cars">
<option value="bmw">BMW</option>
<option value="audi">Audi</option>
</optgroup>
<optgroup label="Japanese Cars">
<option value="toyota">Toyota</option>
</optgroup>
</select>
Use the base tag:
- Make all links open in a new tab by default.
<head>
<base target="_blank">
</head>
Create a live updates region:
- Use aria-live="polite" for non-urgent notifications.
- Add role="status" to the region.
<div role="status" aria-live="polite" aria-atomic="true">
Changes saved successfully
</div>
Add microdata for a person:
- Use itemscope and itemtype="http://schema.org/Person".
- Add itemprop for the name and job title.
<div itemscope itemtype="http://schema.org/Person">
<span itemprop="name">Ahmed Mohamed</span>
<span itemprop="jobTitle">Web Developer</span>
</div>
Improve loading performance:
- Use preload for an important font.
- Use prefetch for a page the user may visit.
<link rel="preload" href="font.woff2" as="font" type="font/woff2" crossorigin>
<link rel="prefetch" href="/en/next-page.html">
Speed up connections to external domains:
- Use dns-prefetch for Google Fonts.
- Add preconnect for a CDN.
<link rel="dns-prefetch" href="//fonts.googleapis.com">
<link rel="preconnect" href="https://cdn.example.com" crossorigin>
Link the manifest file:
- Add a link to manifest.json.
- Add theme-color for the browser.
<link rel="manifest" href="/en/manifest.json">
<meta name="theme-color" content="#4285f4">
Add structured data for an article:
- Use JSON-LD in a script with type="application/ld+json".
- Set @type to Article.
- Add headline, author, datePublished.
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "Article",
"headline": "Learn HTML",
"author": {
"@type": "Person",
"name": "Ahmed Mohamed"
},
"datePublished": "2024-01-01"
}
</script>
Create a fully accessible navigation menu:
- Use nav with aria-label.
- Add role="menubar" to the list.
- Use aria-current="page" for the current page.
<nav aria-label="Main navigation">
<ul role="menubar">
<li role="none">
<a href="/en/" role="menuitem" aria-current="page">Home</a>
</li>
<li role="none">
<a href="/en/about" role="menuitem">About Us</a>
</li>
</ul>
</nav>
Use all types of resource hints:
- dns-prefetch for an external domain.
- preconnect for an API.
- prefetch for the next page.
- preload a critical CSS file.
<link rel="dns-prefetch" href="//cdn.example.com">
<link rel="preconnect" href="https://api.example.com">
<link rel="prefetch" href="/en/next-page.html">
<link rel="preload" href="critical.css" as="style">
Add security meta tags:
- Content Security Policy.
- X-Content-Type-Options.
- Referrer Policy.
<meta http-equiv="Content-Security-Policy" content="default-src 'self'">
<meta http-equiv="X-Content-Type-Options" content="nosniff">
<meta name="referrer" content="no-referrer-when-downgrade">
Create a full head for an SEO-optimized page:
- All essential meta tags.
- Open Graph and Twitter Cards.
- JSON-LD structured data.
- Resource hints.
- Security headers.
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Page Title - Site</title>
<meta name="description" content="A complete description of the page">
<link rel="canonical" href="https://example.com/page">
<!-- Open Graph -->
<meta property="og:title" content="Page Title">
<meta property="og:description" content="Page description">
<meta property="og:image" content="https://example.com/image.jpg">
<meta property="og:url" content="https://example.com/page">
<!-- Twitter -->
<meta name="twitter:card" content="summary_large_image">
<!-- Resource Hints -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="dns-prefetch" href="//cdn.example.com">
<!-- Structured Data -->
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "WebPage",
"name": "Page Title"
}
</script>
</head>