1.1 Answer- HTML CSS Front End Interview Questions
1.1 Answer- HTML CSS Front End Interview Questions
href="#">Home</a></li> method="post">
1. **HTML Definition and Purpose:** <li><a <input type="text"
HTML (HyperText Markup href="#">About</a></li> name="username"
Language) is the standard language <li><a placeholder="Enter your
used to create and design web href="#">Contact</a></li> username"><br>
pages on the Internet. Its purpose is </ul> <textarea name="message"
to structure content by using a </nav> rows="4" cols="50">Enter your
system of tags, which define </header> message here...</textarea><br>
different elements of a webpage. ``` <button
type="submit">Submit</button>
Example: 5. **Document Object Model </form>
```html (DOM):** ```
<html> The DOM represents the structure
<head> of a document as a tree of objects, 9. **Embedding Multimedia
<title>My First HTML which can be manipulated with Elements (`<audio>`, `<video>`,
Page</title> scripting languages like JavaScript. `<embed>`):**
</head> Multimedia elements like
<body> Example: `<audio>`, `<video>`, and
<h1>Hello, World!</h1> ```html `<embed>` are used to embed
<p>This is a paragraph of <script> audio, video, and other media types
text.</p> into web pages.
</body> document.getElementById("demo").i
</html> nnerHTML = "Hello, JavaScript!"; Example:
``` </script> ```html
<div id="demo"></div> <audio controls>
2. **HTML Tags and Attributes:** ``` <source src="audio.mp3"
HTML tags are used to mark up type="audio/mp3">
elements within a document, and 6. **HTML5 vs HTML4 Features:** Your browser does not support
attributes provide additional HTML5 introduced new features the audio tag.
information about those elements or such as semantic elements, </audio>
control their behavior. multimedia support (`<audio>`, ```
`<video>`), canvas for graphics, and
Example: enhanced form controls. 10. **Data Attributes (`data-*`
```html attributes):**
<a Example: `data-*` attributes allow
href="https://www.example.com" ```html developers to store custom data
target="_blank">Visit Example</a> <video controls> directly in HTML elements,
<img src="image.jpg" <source src="movie.mp4" accessible via JavaScript.
alt="Description of the image"> type="video/mp4">
``` Your browser does not support Example:
the video tag. ```html
3. **Block-Level vs Inline </video> <div id="product"
Elements:** ``` data-product-id="12345"
Block-level elements start on a data-category="electronics">
new line and take up the full width 7. **Creating Hyperlinks (`<a>` Product details here
available, while inline elements do tag):** </div>
not start on a new line and only take The `<a>` tag creates hyperlinks to ```
up as much width as necessary. other web pages, files, locations
within the same page, or email 11. **Creating Tables (`<table>`,
Example: addresses. `<tr>`, `<td>`, `<th>`):**
```html Tables in HTML are created using
<div>This is a block-level Example: `<table>` for the table itself, `<tr>` for
element.</div> ```html rows, `<td>` for regular cells, and
<span>This is an inline <a `<th>` for header cells.
element.</span> href="https://www.example.com"
``` target="_blank">Visit Example</a> Example:
``` ```html
4. **Semantic HTML Elements:** <table border="1">
Semantic HTML elements convey 8. **HTML Forms and Form <tr>
meaning rather than just Elements (`<input>`, `<textarea>`, <th>Name</th>
presentation. `<button>`):** <th>Age</th>
HTML forms allow users to input </tr>
Example: data. Form elements like `<input>`, <tr>
```html `<textarea>`, and `<button>` are <td>John</td>
<header> used to create interactive fields and <td>25</td>
<nav> buttons. </tr>
<ul> </table>
Example: ```
```html
1
12. **`<meta>` Tag and Its ```html
Purpose:** <img src="image.jpg" document.getElementById("demo").i
The `<meta>` tag provides alt="Description of the image"> nnerHTML = "Hello, JavaScript!";
metadata about the HTML ``` </script>
document, such as character <div id="demo"></div>
encoding, viewport settings, 17. **Creating Lists (`<ul>`, `<ol>`, ```
keywords, and descriptions. `<dl>`):**
Lists are created using `<ul>` for
Example: unordered lists, `<ol>` for ordered 21. **Global Attributes (`id`, `class`,
```html lists, and `<dl>` for definition lists. `style`, `title`):**
<meta charset="UTF-8"> Global attributes can be applied to
<meta name="description" Example: any HTML element to provide
content="This is a description of the ```html additional information or to style
webpage"> <ul> elements.
``` <li>Item 1</li>
<li>Item 2</li> Example:
13. **`<div>` vs `<span>`:** </ul> ```html
`<div>` is a block-level element ``` <div id="main-content"
used to group larger sections of class="container"
content, while `<span>` is an inline 18. **New HTML5 Form Elements style="background-color: #f0f0f0;"
element used for smaller chunks of (`<datalist>`, `<keygen>`, title="Main Content">
text or inline styling. `<output>`):** Content goes here
HTML5 introduced new form </div>
Example: elements such as `<datalist>` for ```
```html providing autocomplete options,
<div style="color: blue;">This is a `<keygen>` for generating key pairs, 22. **`<section>` vs `<div>`:**
block-level element.</div> and `<output>` for displaying `<section>` is a semantic HTML5
<span style="font-weight: calculation results. element used to define sections in a
bold;">This is an inline document, while `<div>` is a generic
element.</span> Example: container.
``` ```html
<form> Example:
14. **`<iframe>` Tag Usage:** <input list="browsers"> ```html
`<iframe>` is used to embed <datalist id="browsers"> <section>
another HTML page within the <option value="Chrome"> <h2>Section Title</h2>
current page, typically used for <option value="Firefox"> <p>Section content...</p>
embedding maps, videos, or other </datalist> </section>
external content. </form> ```
```
Example: 23. **Responsive Layouts with
```html 19. **`<canvas>` Element for HTML (meta viewport):**
<iframe Graphics:** Responsive layouts are achieved
src="https://www.google.com/maps/e `<canvas>` allows for dynamic using CSS media queries along with
mbed?pb=!1m18!1m12!1m3!..."> rendering of graphics, animations, the `<meta>` viewport tag to control
Your browser does not support and interactive content using the layout on different devices.
iframes. JavaScript.
</iframe> Example:
``` Example: ```html
```html <meta name="viewport"
15. **Including External Resources <canvas id="myCanvas" content="width=device-width,
(CSS, JS):** width="200" initial-scale=1.0">
External CSS and JavaScript files height="100"></canvas> ```
are included in HTML documents ```
using `<link>` and `<script>` tags 24. **`<!DOCTYPE html>`
respectively. 20. **`<script>`, `<noscript>`, and Declaration:**
`<template>` Tags:** Specifies the HTML version and
Example: `<script>` is used to embed or ensures proper rendering by modern
```html reference JavaScript code, web browsers.
<link rel="stylesheet" `<noscript>` provides alternate
href="styles.css"> content when JavaScript is disabled, Example:
<script src="script.js"></script> and `<template>` holds client-side ```html
``` content that should not be rendered <!DOCTYPE html>
when the page is loaded but can be <html lang="en">
16. **alt Attribute in Images:** instantiated later. <head>
The `alt` attribute provides <meta charset="UTF-8">
alternative text for images, useful for Example: <meta name="viewport"
accessibility and when the image ```html content="width=device-width,
cannot be displayed. <script> initial-scale=1.0">
<title>My HTML Document</title>
Example:
2
<link rel="stylesheet" Example: 4. **CSS Box Model:**
href="styles.css"> ```html The CSS box model describes the
<script src="script.js" <style> rectangular boxes that are generated
defer></script> body { for elements in the document tree.
</head> font-family: Arial, sans-serif;
<body> background-color: #f0f0f0; Example:
<header> } ```css
<h1>Website Header</h1> h1 { .box {
<nav> color: blue; width: 200px;
<ul> text-align: center; padding: 20px;
<li><a } border: 1px solid #ccc;
href="#">Home</a></li> </style> margin: 10px;
<li><a ``` }
href="#">About</a></li> ```
<li><a 2. **CSS Selectors:**
href="#">Contact</a></li> CSS selectors are patterns used to 5. **Differences Between Classes
</ul> select and style elements in an and IDs:**
</nav> HTML document. Classes can be used multiple
</header> times in an HTML document, while
Example: IDs should be unique. IDs have
<section> ```css higher specificity than classes.
<h2>Main Content /* Element selector */
Section</h2> p{ Example:
<p>This section contains the font-size: 16px; ```html
main content of the webpage.</p> } <div class="box">This is a
</section> box.</div>
/* Class selector */ <div id="unique-box">This is a
<footer> .important { unique box.</div>
<p>© 2024 My Website. color: red; ```
All rights reserved.</p> }
</footer> 6. **Applying CSS (Inline, Internal,
</body> /* ID selector */ External):**
</html> #header { CSS can be applied inline within
``` background-color: #333; HTML tags, internally in `<style>`
color: white; tags within the `<head>` of an HTML
25. **Handling Broken Images } document, or externally via separate
(`onerror` attribute):** ``` CSS files linked to the HTML
The `onerror` attribute in `<img>` document.
tags allows specifying a JavaScript 3. **CSS Specificity and
function to handle situations where Inheritance:** Example:
an image fails to load. Specificity determines which CSS ```html
rule applies to an element. <!-- Inline CSS -->
Example: Inheritance allows styles applied to <div style="color: red;">This text is
```html parent elements to be inherited by red.</div>
<img src="image.jpg" their child elements.
alt="Description of image" <!-- Internal CSS -->
onerror="this.src='placeholder.jpg';"> Example: <style>
``` ```html .paragraph {
<style> font-size: 16px;
These examples illustrate how /* Specificity example */ line-height: 1.5;
HTML elements, attributes, and .container div { }
features are used to create color: blue; /* Lower </style>
structured, semantic, and interactive specificity */ <div class="paragraph">This is a
web pages. } paragraph styled internally.</div>
div#special {
color: red; /* Higher <!-- External CSS -->
CSS specificity */ <link rel="stylesheet"
} href="styles.css">
Certainly! Here are explanations and ```
examples for each CSS topic: /* Inheritance example */
.parent { 7. **CSS Positioning (Static,
1. **CSS Definition and Purpose:** font-size: 18px; Relative, Absolute, Fixed, Sticky):**
CSS (Cascading Style Sheets) is a } CSS positioning determines how
language used for describing the .child { an element is positioned in the
presentation of a document written in /* Inherits font-size from document flow.
HTML or XML. It controls the layout, parent */
colors, fonts, and other visual } Example:
aspects of web pages. </style> ```css
``` .box {
3
position: relative; /* or absolute, } .clearfix::after {
fixed, static, sticky */ ``` content: "";
top: 20px; display: table;
left: 50px; 12. **CSS Transitions and clear: both;
} Animations:** }
``` CSS transitions and animations ```
allow you to animate changes to
8. **CSS Flexbox Layout:** CSS properties. 16. **CSS Z-index and Stacking
Flexbox is a layout model that Context:**
allows responsive elements within a Example: `z-index` specifies the stacking
container to be automatically ```css order of positioned elements.
arranged depending on the screen .box { Stacking context defines how
size. width: 100px; elements are stacked relative to
height: 100px; each other.
Example: background-color: blue;
```css transition: width 2s, height 2s; Example:
.container { } ```css
display: flex; .box:hover { .box1 {
justify-content: space-around; width: 200px; position: relative;
align-items: center; height: 200px; z-index: 2;
} } }
``` ``` .box2 {
position: relative;
9. **CSS Grid Layout:** 13. **CSS Media Queries for z-index: 1;
CSS Grid Layout is a Responsive Design:** }
two-dimensional layout system for Media queries allow styles to be ```
CSS that allows you to design applied depending on the
complex web layouts more easily. characteristics of the device, such as 17. **CSS Units (px, em, rem, %, vw,
screen width, height, and orientation. vh):**
Example: CSS units determine the size or
```css Example: position of elements relative to other
.grid-container { ```css elements or the viewport.
display: grid; @media screen and (max-width:
grid-template-columns: 1fr 1fr 600px) { Example:
1fr; body { ```css
grid-gap: 10px; background-color: lightblue; .box {
} } width: 200px;
``` } font-size: 1.2em;
``` padding: 2rem;
10. **CSS Display Property:** margin-top: 10%;
The `display` property specifies 14. **Differences Between `display: height: 50vw;
the display behavior of an element. none` and `visibility: hidden`:** }
`display: none` removes the ```
Example: element from the document flow,
```css whereas `visibility: hidden` hides the 18. **CSS Variables (Custom
.inline { element but keeps its space in the Properties):**
display: inline; layout. CSS variables allow for reusable
} values throughout a stylesheet.
.block { Example:
display: block; ```css Example:
} .hidden { ```css
``` display: none; :root {
} --primary-color: #007bff;
11. **CSS Pseudo-classes and .invisible { }
Pseudo-elements:** visibility: hidden; .box {
Pseudo-classes and } color: var(--primary-color);
pseudo-elements style elements ``` }
based on their state or position in the ```
document tree. 15. **CSS `float` Property and
Clearfix:** 19. **CSS `box-sizing` Property:**
Example: The `float` property positions an The `box-sizing` property defines
```css element to the left or right in its how the total width and height of an
/* Pseudo-class */ container. Clearfix is used to clear element is calculated.
a:hover { floated elements.
color: red; Example:
} Example: ```css
```css .box {
/* Pseudo-element */ .float-left { box-sizing: border-box;
p::first-line { float: left; width: 200px;
font-weight: bold; } padding: 20px;
4
border: 1px solid black; and functions, which are then ```css
} compiled into standard CSS. @supports (display: grid) {
``` .grid-container {
Example (SASS): display: grid;
20. **CSS Combinators ```scss grid-template-columns: 1fr
(Descendant, Child, Adjacent $primary-color: #007bff; 1fr;
Sibling, General Sibling):** .box { }
CSS combinators are used to color: $primary-color; }
select elements based on their } ```
relationship with other elements. ```
Example (Polyfill):
Example: 24. **Including Custom Fonts ```html
```css (`@font-face`, Google Fonts):** <script
/* Descendant combinator */ Custom fonts can be included src="https://cdn.polyfill.io/v3/polyfill.
.container p { using `@font-face` for locally hosted min.js"></script>
font-size: 16px; fonts or Google Fonts for web fonts. ```
}
/* Child combinator */ These examples cover various
.container > ul { Example (`@font-face`): aspects of CSS, from basic styling to
list-style-type: none; ```css advanced layout techniques and
} @font-face { ensuring compatibility across
/* Adjacent sibling combinator */ font-family: 'MyCustomFont'; different browsers.
h1 + p { src: url('mycustomfont.woff2')
margin-top: 0; format('woff2'),
} url('mycustomfont.woff') Front End
/* General sibling combinator */ format('woff');
h2 ~ p { font-weight: normal; Given the extensive list of topics, I'll
font-style: italic; font-style: normal; answer each with concise
} } explanations and examples where
``` .custom-font { applicable:
font-family: 'MyCustomFont',
21. **CSS Sprites:** Arial, sans-serif; 1. **HTML Definition and Purpose:**
CSS sprites combine multiple } HTML (HyperText Markup
images into a single image, reducing ``` Language) is the standard language
the number of server requests. used to create and design web
Example (Google Fonts): pages on the Internet. Its purpose is
Example: ```html to structure content using a system
```css <link rel="stylesheet" of tags that define different elements
.icon { href="https://fonts.googleapis.com/cs of a webpage.
background-image: s?family=Roboto">
url('sprites.png'); <style> Example:
background-position: -20px .google-font { ```html
-40px; font-family: 'Roboto', <!DOCTYPE html>
width: 30px; sans-serif; <html>
height: 30px; } <head>
} </style> <title>My First HTML
``` ``` Page</title>
</head>
22. **Centering Elements 25. **Handling Browser Compatibility <body>
Horizontally and Vertically:** (Vendor Prefixes, Feature Queries, <h1>Hello, World!</h1>
CSS techniques to center Polyfills):** <p>This is a paragraph of
elements horizontally and vertically Techniques to ensure CSS text.</p>
within their containers. features work across different </body>
browsers, including using vendor </html>
Example: prefixes, feature queries, and ```
```css polyfills.
.center { 2. **CSS Selectors:**
position: absolute; Example (Vendor Prefix): CSS selectors are patterns used to
top: 50%; ```css select and style elements in HTML
left: 50%; .box { documents.
transform: translate(-50%, display: -webkit-box; /* Safari,
-50%); iOS, Android */ Example:
} display: -moz-box; /* Firefox ```css
``` */ /* Selects all <p> elements */
display: box; /* Standard p{
23. **CSS Preprocessors (SASS, */ color: blue;
LESS):** } }
CSS preprocessors extend CSS ```
with variables, nested rules, mixins,
Example (Feature Query):
5
/* Selects elements with class padding, and the actual content area
"container" */ Example: of an element.
.container { ```html
width: 100%; <style> Example:
} /* Specificity example */ ```html
p{ <style>
/* Selects element with id "header" color: blue; /* Specificity: 0, .box {
*/ 0, 1 */ width: 200px;
#header { } height: 100px;
background-color: #ccc; .special { padding: 20px;
} color: red; /* Specificity: 0, 0, border: 1px solid #000;
``` 10 */ margin: 10px;
} background-color: #ccc;
3. **JavaScript Functions and #unique { }
Scope:** color: green; /* Specificity: 0, </style>
Functions in JavaScript are blocks 1, 0 */ <div class="box">Content</div>
of reusable code. Scope defines } ```
where variables and functions are </style>
accessible within a program. <p>This text is blue.</p> 9. **ES6 Features (let, const, arrow
<p class="special">This text is functions, template literals, etc.):**
Example: red.</p> ES6 introduced several new
```javascript <p id="unique">This text is features to JavaScript such as `let`
// Function declaration green.</p> and `const` for variable declaration,
function greet(name) { ``` arrow functions for concise function
return `Hello, ${name}!`; syntax, and template literals for
} 6. **Data Types and Variables:** easier string interpolation.
JavaScript has several data types
// Function call including strings, numbers, Example:
console.log(greet('Alice')); // booleans, objects, arrays, and more. ```javascript
Outputs: Hello, Alice! Variables are used to store data // Arrow function example
values. const add = (a, b) => a + b;
// Scope example
let x = 10; Example: // Template literal example
function testScope() { ```javascript let name = 'Alice';
let y = 20; let message = 'Hello'; // String console.log(`Hello, ${name}!`);
console.log(x); // Accessible: let number = 42; // Number ```
Outputs 10 let isTrue = true; // Boolean
console.log(y); // Accessible: let person = { // Object 10. **Document Object Model
Outputs 20 name: 'Alice', (DOM):**
} age: 30 The DOM is a programming
console.log(x); // Accessible: }; interface for web documents. It
Outputs 10 let colors = ['red', 'blue']; // Array represents the structure of a
console.log(y); // Not accessible: ``` document as a tree of objects,
Throws ReferenceError allowing JavaScript to manipulate
``` 7. **Semantic HTML Elements:** and modify the content and structure
Semantic HTML elements convey of a webpage.
4. **Block-Level vs Inline meaning rather than just
Elements:** presentation. Example:
Block-level elements start on a ```html
new line and take up the full width Example: <script>
available, while inline elements do ```html
not start on a new line and only take <header> document.getElementById("demo").i
up as much width as necessary. <nav> nnerHTML = "Hello, JavaScript!";
<ul> </script>
Example: <li><a <div id="demo"></div>
```html href="#">Home</a></li> ```
<div>This is a block-level <li><a
element.</div> href="#">About</a></li> These examples cover a range of
<span>This is an inline <li><a fundamental topics in HTML, CSS,
element.</span> href="#">Contact</a></li> and JavaScript, providing clear
``` </ul> explanations and practical code
</nav> snippets where applicable. Let me
5. **CSS Specificity and </header> know if you'd like to continue with
Inheritance:** ``` more topics!
Specificity determines which CSS
rule is applied when multiple rules 8. **CSS Box Model:** Certainly! Let's continue with more
could apply to the same element. The CSS box model describes the topics:
Inheritance allows styles applied to rectangular boxes that are generated
parent elements to be inherited by for elements in the document tree. It 11. **Differences Between Classes
their child elements. consists of margins, borders, and IDs:**
6
Classes and IDs are both used for externally (linking to an external CSS CSS positioning determines how
styling HTML elements, but IDs are file). an element is positioned within its
unique and can only be applied to parent container or the viewport.
one element per page, while classes Example:
can be applied to multiple elements. ```html Example:
<!-- Inline CSS --> ```html
Example: <div style="color: blue;">This is <style>
```html styled inline.</div> .box {
<style> position: relative; /* Relative
/* Class selector */ <!-- Internal CSS --> positioning */
.highlight { <style> top: 20px;
background-color: yellow; .container { left: 30px;
} width: 80%; }
margin: 0 auto;
/* ID selector */ } .fixed {
#unique { </style> position: fixed; /* Fixed
color: blue; positioning */
} <!-- External CSS --> top: 0;
</style> <link rel="stylesheet" right: 0;
<p class="highlight">This href="styles.css"> }
paragraph has a class.</p> ``` </style>
<p id="unique">This paragraph <div class="box">Relative
has an ID.</p> 15. **DOM Manipulation with Positioning</div>
``` JavaScript:** <div class="fixed">Fixed
DOM manipulation involves Positioning</div>
12. **JavaScript Arrays and modifying the structure, style, or ```
Objects:** content of a webpage using
Arrays and objects are used to JavaScript. 18. **Event Handling in JavaScript:**
store multiple values in JavaScript. Event handling allows JavaScript
Arrays are ordered lists of values, Example: to respond to user actions like clicks,
while objects are collections of ```html mouse movements, key presses,
key-value pairs. <script> etc.
// Change text content of an
Example: element Example:
```javascript ```html
// Array example document.getElementById("demo").i <button onclick="alert('Button
let colors = ['red', 'green', 'blue']; nnerHTML = "Updated content"; clicked!')">Click Me</button>
```
// Object example // Create a new element and
let person = { append it to the DOM 19. **HTML Forms and Form
name: 'Alice', let newDiv = Elements (`<input>`, `<textarea>`,
age: 30, document.createElement('div'); `<button>`):**
city: 'New York' newDiv.textContent = 'New HTML forms allow users to input
}; Element'; data using form elements like
``` `<input>`, `<textarea>`, `<button>`,
document.body.appendChild(newDiv `<select>`, etc.
13. **HTML5 vs HTML4 Features:** );
HTML5 introduced new features </script> Example:
such as semantic elements <div id="demo">Initial ```html
(`<header>`, `<footer>`), multimedia content</div> <form action="/submit-form"
support (`<audio>`, `<video>`), ``` method="post">
canvas for graphics, local storage, <input type="text"
and improved form controls. 16. **Creating Hyperlinks (`<a>` name="username"
tag):** placeholder="Enter your
Example: The `<a>` tag creates hyperlinks username"><br>
```html to other web pages, files, locations <textarea name="message"
<!-- Video element in HTML5 --> within the same page, or email rows="4" cols="50">Enter your
<video controls> addresses. message here...</textarea><br>
<source src="movie.mp4" <button
type="video/mp4"> Example: type="submit">Submit</button>
Your browser does not support ```html </form>
the video tag. <a ```
</video> href="https://www.example.com"
``` target="_blank">Visit Example</a> 20. **CSS Flexbox Layout:**
``` Flexbox is a layout model in CSS
14. **Applying CSS (Inline, Internal, designed for laying out elements in a
External):** 17. **CSS Positioning (Static, single direction—either horizontally
CSS can be applied inline (directly Relative, Absolute, Fixed, Sticky):** or vertically.
in the HTML), internally (within a
`<style>` tag in the `<head>`), or Example:
7
```html }
<style> fetchData();
.flex-container { ``` let myFunction = outerFunction();
display: flex; myFunction(); // Outputs: Hello
justify-content: 22. **Embedding Multimedia ```
space-between; Elements (`<audio>`, `<video>`,
} `<embed>`):** 25. **Data Attributes (`data-*`
.flex-item { Multimedia elements like attributes):**
flex: 1; `<audio>`, `<video>`, and `data-*` attributes allow
} `<embed>` are used to embed developers to store custom data
</style> audio, video, and other media types directly in HTML elements,
<div class="flex-container"> into web pages. accessible via JavaScript.
<div class="flex-item">Item
1</div> Example: Example:
<div class="flex-item">Item ```html ```html
2</div> <video controls> <div id="product"
<div class="flex-item">Item <source src="movie.mp4" data-product-id="12345"
3</div> type="video/mp4"> data-category="electronics">
</div> Your browser does not support Product details here
``` the video tag. </div>
</video> <script>
These examples provide practical ``` let productDiv =
illustrations of various HTML, CSS, document.getElementById('product');
and JavaScript concepts. Let me 23. **CSS Grid Layout:**
know if you'd like to continue with CSS Grid Layout provides a console.log(productDiv.dataset.prod
more topics or if there's something two-dimensional grid-based layout uctId); // Outputs: 12345
specific you'd like to explore further! system, making it easier to design
Certainly! Let's continue exploring complex web layouts. console.log(productDiv.dataset.categ
more topics: ory); // Outputs: electronics
Example: </script>
21. **JavaScript Promises and ```html ```
Async/Await:** <style>
Promises are used for .grid-container { 26. **CSS Display Property:**
asynchronous programming in display: grid; The CSS `display` property
JavaScript, allowing execution of grid-template-columns: 1fr 1fr specifies the display behavior (block,
code that depends on the result of a 1fr; inline, flex, etc.) of an element.
previous operation. Async functions gap: 10px;
simplify asynchronous code with the } Example:
`async` and `await` keywords. .grid-item { ```html
background-color: #ccc; <style>
Example: padding: 20px; .block {
```javascript } display: block;
// Using Promises </style> width: 100px;
function getData() { <div class="grid-container"> height: 100px;
return new Promise((resolve, <div class="grid-item">Item background-color: red;
reject) => { 1</div> }
setTimeout(() => { <div class="grid-item">Item
resolve('Data fetched 2</div> .inline {
successfully'); <div class="grid-item">Item display: inline;
}, 2000); 3</div> width: 100px;
}); </div> height: 100px;
} ``` background-color: blue;
}
getData().then(data => { 24. **JavaScript Closures:** </style>
console.log(data); // Outputs: Closures are functions that <div class="block">Block
Data fetched successfully remember the lexical scope in which Element</div>
}).catch(error => { they were created, even when the <span class="inline">Inline
console.error(error); function is executed outside that Element</span>
}); scope. ```
16