HTML, CSS
HTML, CSS
1. What is HTML?
Answer: HTML (HyperText Markup Language) is the standard markup language used to create web
pages. It structures content on the web.
Answer: A tag is a keyword enclosed within angle brackets that defines how a browser should display
content.
Answer: HTML is less strict in syntax, whereas XHTML is an XML-based version of HTML with stricter
syntax rules.
Answer: Void elements, like <img>, <br>, and <hr>, do not have closing tags.
Answer: It informs the browser about the HTML version to render the page correctly.
Answer: Ordered lists (<ol>), unordered lists (<ul>), and definition lists (<dl>).
Answer: Use the <a> tag with the href attribute: <a href="url">link text</a>.
Answer: <div> is a block-level element used to group sections, whereas <span> is an inline element used
to group small sections within a block.
Answer: It provides alternative text for an image, which is displayed if the image cannot be loaded.
Answer: Use the <video> tag with src attribute: <video src="video.mp4" controls></video>.
Answer: It provides metadata about the HTML document, such as charset, author, and description.
Answer: It specifies where to open the linked document. For example, target="_blank" opens the link in
a new tab.
13. What is an HTML attribute?
Answer: Attributes provide additional information about an element, typically in name-value pairs like
class="classname".
Answer: Elements that clearly describe their meaning to both the browser and the developer, such as
<header>, <footer>, and <article>.
Answer: Use <table>, <tr> (table row), <td> (table data), and <th> (table header) tags.
Answer: id is a unique identifier for a single element, while class can be used on multiple elements.
Answer: Use the <form> tag with input fields like <input>, <textarea>, and <select>.
Answer: It specifies where to send the form data when the form is submitted.
Answer: Elements that do not start on a new line and only take up as much width as necessary, such as
<a>, <span>, and <img>.
Answer: Elements that start on a new line and take up the full width available, like <div>, <p>, and <h1>.
Answer: Wrap the <img> tag inside an <a> tag: <a href="url"><img src="image.jpg"></a>.
Answer: It defines the key that is sent to the server with the form data.
Answer: <br> is used to insert a line break, while <hr> inserts a horizontal line.
Answer: It allows you to store custom data private to the page or application.
28. How do you specify the character encoding for an HTML document?
Answer: <b> is for stylistic bolding, while <strong> indicates strong importance and is semantically
meaningful.
Answer: It contains meta-information about the HTML document, such as title, links to stylesheets, and
scripts.
Answer: <i> is for italicized text without semantic importance, while <em> indicates emphasized text.
Answer: Use the <script> tag either in the <head> or before the closing </body> tag.
Answer: It specifies the relationship between the current document and the linked document/resource.
Answer: CSS can be included inline, internally using the <style> tag, or externally using the <link> tag.
Answer: It sets the title of the HTML document, which is displayed on the browser's title bar or tab.
Answer: It specifies multiple image sources for responsive images, allowing the browser to choose the
most appropriate one based on the device's resolution.
Answer: It defines an alternate content to display if the browser does not support JavaScript.
38. What is the difference between <script> tag with defer and async attributes?
Answer: defer loads the script after the HTML document is completely parsed, while async loads the
script asynchronously and does not wait for the HTML document to finish loading.
Answer: It specifies that the target should be downloaded when the user clicks on the hyperlink.
Answer: It sets the base URL for all relative URLs in the document.
Answer: <figure> is used to group media content like images, and <figcaption> is used to provide a
caption for that content.
Answer: It declares the language of the HTML document, improving accessibility and SEO.
Answer: <link> is used to link external resources, like stylesheets, while <a> is used to create hyperlinks
to other pages or locations within the page.
Answer: Use the <meta name="viewport" content="width=device-width, initial-scale=1.0"> tag and CSS
media queries to make the page responsive.
Answer: <details> creates a collapsible section, and <summary> defines the visible heading of the
section.
Answer: <nav> defines a section of navigation links, while <footer> defines the footer section of the
document.
CSS-
1.What is CSS?
Answer: CSS (Cascading Style Sheets) is a stylesheet language used to describe the presentation
of a document written in HTML or XML. It controls the layout of multiple web pages at once.
Answer: HTML (HyperText Markup Language) is used to create the structure of a web page,
while CSS is used to control the appearance and layout of the HTML elements.
Answer:
1. Inline CSS: Applied directly to HTML elements using the style attribute.
2. Internal CSS: Defined within a <style> tag inside the HTML <head> section.
3. External CSS: Written in a separate .css file and linked to the HTML document.
Answer: The class selector can be used on multiple elements, while the id selector is unique to a
single element. id is also more specific than class.
Answer: The CSS Box Model consists of four parts: content, padding, border, and margin. The
content is surrounded by padding, then the border, and finally the margin.
Answer: The float property is used to align elements to the left or right of their container,
allowing other elements to wrap around them.
Answer: The display property controls the layout of elements. Common values include:
Answer:
Answer:
css
Copy code
display: flex;
align-items: center;
justify-content: center;
Answer: A CSS preprocessor is a scripting language that extends CSS with variables, nesting, and
functions. Examples include SASS, LESS
12. What is the difference between relative, absolute, fixed, and sticky positioning?
Answer:
Answer: The z-index property controls the stacking order of elements. Elements with a higher z-
index appear on top of those with a lower z-index.
15. What is Flexbox, and how is it different from CSS Grid?
Answer: Flexbox is a one-dimensional layout system used for arranging items in rows or
columns, while CSS Grid is a two-dimensional layout system that allows for more complex
layouts with both rows and columns.
Answer: Specificity determines which CSS rule is applied by the browser when multiple rules
could apply to the same element.
Answer: em is relative to the font size of the parent element, while rem is relative to the root
(HTML) element's font size.
18. What are media queries, and how are they used?
Answer: Media queries allow CSS to apply styles based on the device's characteristics, such as
screen width, height, resolution, etc. They are used to create responsive designs.
Answer: Transitions allow you to change property values smoothly (for hover or focus states),
while animations allow for more complex sequences of keyframes, providing more control over
the animation.
22. What are CSS variables, and how are they used?
Answer: CSS variables (custom properties) are entities defined by CSS that contain specific
values to be reused throughout a document.
24. What are CSS Sprites, and how are they used?
Answer: CSS sprites are a way to reduce the number of HTTP requests by combining multiple
images into a single file.
25. What is the overflow property, and what are its values?
Answer: The overflow property controls what happens to content that overflows an element's
box. Values include visible, hidden, scroll, and auto.
Answer: You can hide an element using display: none; or visibility: hidden;.
Answer: The box-sizing property defines how the width and height of an element are calculated:
content-box (default) or border-box (includes padding and border).
28. What is the purpose of the clear property?
Answer: The clear property is used to prevent elements from wrapping around floated elements.
It can have values like left, right, or both.
Answer: The @import rule is used to import one stylesheet into another.
Answer: nth-child() selects the nth child regardless of type, while nth-of-type() selects the nth
child of a specific type.
Answer: The calc() function performs calculations to determine CSS property values, combining
different units (e.g., width: calc(100% - 50px);).
34. What is the difference between visibility: hidden; and opacity: 0;?
Answer: visibility: hidden; hides the element but keeps it in the layout, while opacity: 0; makes
it invisible but still interactable.
Answer: The line-height property controls the amount of space between lines of text,
improving readability.
Answer: The content property is used with pseudo-elements like ::before and ::after to insert
content.
Answer:
o Descendant ( )
o Child (>)
Answer: justify-content aligns items along the main axis (horizontally by default), while align-
items aligns them along the cross axis (vertically by default).
Answer: The clip-path property creates a clipping region that determines which parts of an
element are visible.
Answer: The pointer-events property controls whether an element can be the target of mouse
events, with values like auto, none, etc.