HTML, CSS, and JavaScript Viva Questions with Answers
HTML Questions
Q: What is HTML?
A: HTML stands for HyperText Markup Language. It structures web content using tags.
Q: What are tags in HTML?
A: Tags are used to define elements in HTML. Example: <p>, <h1>, <img>.
Q: Difference between <div> and <span>?
A: <div> is block-level, <span> is inline.
Q: Difference between id and class?
A: id is unique per page; class can be reused for multiple elements.
Q: What are semantic elements?
A: Elements that convey meaning, e.g., <header>, <footer>, <article>.
Q: How to create a hyperlink?
A: <a href="https://example.com">Visit</a>
Q: How to add an image?
A: <img src="image.jpg" alt="Description">
Q: Purpose of <head> and <body>?
A: <head> contains metadata; <body> contains visible content.
Q: What is a self-closing tag?
A: A tag that doesn't need a closing tag. Example: <br>, <img>
Q: Block vs Inline elements?
A: Block takes full width (e.g., <div>); Inline only takes required space (e.g., <span>).
CSS Questions
Q: What is CSS?
A: CSS stands for Cascading Style Sheets. It styles HTML elements.
Q: Types of CSS?
A: Inline, Internal, External
Q: id vs class selector?
A: id uses #; class uses . and can be reused.
Q: What is a pseudo-class?
A: Used to define element states. Example: a:hover
Q: Box Model?
A: Includes Content, Padding, Border, Margin.
Q: Use of position property?
A: static, relative, absolute, fixed, sticky
Q: How to center a div?
A: margin: 0 auto; with defined width.
Q: What is z-index?
A: Controls stack order of overlapping elements.
Q: em vs rem vs px?
A: px is fixed; em relative to parent; rem relative to root.
Q: What are media queries?
A: Used for responsive design. Example: @media (max-width: 600px) {...}
JavaScript Questions
Q: What is JavaScript?
A: A scripting language to make web pages interactive.
Q: JS vs Java?
A: JS is interpreted and web-based; Java is compiled and general-purpose.
Q: How to declare variables?
A: var, let, const
Q: Data types?
A: String, Number, Boolean, Object, Array, Undefined, Null
Q: What is an array?
A: let fruits = ["Apple", "Banana"];
Q: What is a function?
A: A block of code that performs a task.
Q: What is an event?
A: An action like click, hover. Example: onclick
Q: What is DOM?
A: Document Object Model to interact with HTML via JS.
Q: == vs ===?
A: == compares value; === compares value and type.
Q: Types of loops?
A: for, while, do...while