HTML Questions:
What is the difference between HTML and HTML5?
- HTML5 introduces new features like
<article>,<header>, multimedia support, local storage, and improved form elements over previous HTML versions.
- HTML5 introduces new features like
What are void (self-closing) elements in HTML?
- Elements like
<img>,<br>,<hr>, which don’t have closing tags.
- Elements like
Explain the structure of an HTML document.
- An HTML document includes
<!DOCTYPE>,<html>,<head>(with metadata), and<body>for content.
- An HTML document includes
What is the purpose of the
altattribute in an<img>tag?- Provides alternative text if the image cannot be displayed and improves accessibility for visually impaired users.
What are semantic elements in HTML?
- Elements like
<header>,<article>, and<footer>, which convey specific meaning about the structure of content.
- Elements like
What is the difference between inline, block, and inline-block elements?
- Inline elements (
<span>) flow within the content; block elements (<div>) take up full width; inline-block elements behave like inline but respect width and height.
- Inline elements (
How do you create a hyperlink in HTML?
- Use the
<a>tag:<a href="url">Link text</a>.
- Use the
Explain the difference between
localStorageandsessionStorage.localStoragepersists data across sessions, whilesessionStoragestores data only for the current session.
What is the difference between
<section>and<div>?<section>is semantic representing a distinct section of content;<div>is non-semantic, used for generic container elements.
What are data attributes in HTML? How are they used?
- Custom attributes prefixed with
data-, used to store extra information for DOM elements, e.g.,<div data-id="123"></div>.
- Custom attributes prefixed with
CSS Questions:
What is the CSS box model?
- It consists of content, padding, border, and margin, defining how elements are sized and spaced.
Explain the difference between margin and padding.
- Padding is space inside an element, while margin is space outside it.
- Padding is space inside an element, while margin is space outside it.
What are the different ways to apply CSS to an HTML document?
- Inline styles, internal styles (
<style>tag in the<head>), and external stylesheets (<link>tag).
- Inline styles, internal styles (
What is a CSS selector? Can you name a few common ones?
- A selector targets HTML elements to apply styles. Common ones include element (
h1), class (.className), and ID (#idName).
- A selector targets HTML elements to apply styles. Common ones include element (
What are pseudo-classes and pseudo-elements in CSS?
- Pseudo-classes (
:hover,:focus) style elements based on their state; pseudo-elements (::before,::after) style parts of elements.
- Pseudo-classes (
Explain the concept of specificity in CSS.
- Specificity determines which CSS rule is applied, based on the weight of selectors (ID > class > element).
How do media queries work in responsive design?
- Media queries apply CSS rules based on device characteristics like screen width:
@media (max-width: 600px) {}.
- Media queries apply CSS rules based on device characteristics like screen width:
What is Flexbox and how does it work?
- Flexbox is a layout model that arranges elements in rows or columns, distributing space efficiently with properties like
justify-contentandalign-items.
- Flexbox is a layout model that arranges elements in rows or columns, distributing space efficiently with properties like
What is CSS Grid? How is it different from Flexbox?
- CSS Grid is a two-dimensional layout system for creating complex layouts, while Flexbox is one-dimensional (row or column).
- CSS Grid is a two-dimensional layout system for creating complex layouts, while Flexbox is one-dimensional (row or column).
How do you center an element vertically and horizontally using CSS?
- Using Flexbox:
display: flex; justify-content: center; align-items: center;or CSS Grid:display: grid; place-items: center;
- Using Flexbox:
