Front End Developer Interview Questions for Freshers
Front End Developer Interview Questions for Freshers cover basic web development skills, responsive design principles, and JavaScript fundamentals that companies expect from new graduates. Starting your career as a front end developer means you need to understand HTML, CSS, and JavaScript well enough to build user-friendly websites and applications.
This interview guide includes Front End Developer Interview Questions for Freshers who are looking for their first job in web development, covering topics like DOM manipulation, CSS frameworks, version control systems, and modern development tools.
These Front End Developer Interview Questions for Freshers will help you show your coding abilities, explain your understanding of web standards, and prove you’re ready to create engaging user experiences in today’s digital world.
Entry Level Front End Developer Interview Questions for Freshers
Que 1. What is HTML, and why is it important for web development?
Answer:
HTML (HyperText Markup Language) is the standard language for creating web pages, defining their structure using elements like <div>
, <p>
, and <a>
. It’s essential for building the foundation of web content, enabling browsers to render text, images, and links.
Que 2. What is the difference between HTML and HTML5?
Answer:
HTML is the general markup language, while HTML5 is its latest version, introducing semantic elements (e.g., <header>
, <footer>
), multimedia tags (<video>
, <audio>
), and APIs like Canvas and Geolocation. HTML5 improves accessibility and reduces reliance on plugins like Flash.
Que 3. What is CSS, and what is its role in web development?
Answer:
CSS (Cascading Style Sheets) styles HTML elements, controlling layout, colors, fonts, and responsiveness. It separates presentation from content, enhancing user experience and maintainability.
body {
background-color: #f0f0f0;
font-family: Arial, sans-serif;
}
Que 4. What is the box model in CSS?
Answer:
The CSS box model represents an element’s structure, consisting of content, padding, border, and margin. It affects spacing and sizing in layouts.
div {
width: 100px; /* Content width */
padding: 10px;
border: 5px solid black;
margin: 15px;
}
Que 5. What is the difference between block, inline, and inline-block display properties in CSS?
Answer:
block
: Elements take full width, stack vertically (e.g.,<div>
).inline
: Elements sit inline, only take content width (e.g.,<span>
).inline-block
: Inline but allows width/height settings, respecting margins/padding.
span { display: inline-block; width: 100px; }
Que 6. What is JavaScript, and how does it enhance web pages?
Answer:
JavaScript is a programming language that adds interactivity to web pages, enabling dynamic content, form validation, and event handling. It runs in browsers, manipulating the DOM to create responsive user experiences.
document.getElementById('btn').addEventListener('click', () => alert('Clicked!'));
Que 7. What is the DOM, and how do you interact with it?
Answer:
The DOM (Document Object Model) is a tree-like representation of a web page’s structure. JavaScript interacts with it using methods like getElementById
, querySelector
, or appendChild
to modify elements dynamically.
const div = document.createElement('div');
div.textContent = 'Hello';
document.body.appendChild(div);
Que 8. What is the difference between let, const, and var in JavaScript?
Answer:
var
: Function-scoped, hoisted, allows redeclaration (legacy).let
: Block-scoped, reassignable, not hoisted.const
: Block-scoped, immutable binding (but object properties can change).
let x = 1; // Reassignable
const y = 2; // Fixed binding
var z = 3; // Avoid in modern JS
Que 9. How do you center a div horizontally and vertically in CSS?
Answer:
Use Flexbox, Grid, or absolute positioning. Flexbox is a common approach:
.parent {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
Que 10. What is a media query in CSS, and how is it used?
Answer:
Media queries apply styles based on device characteristics like screen size. They enable responsive design for different devices.
@media (max-width: 600px) {
.container {
font-size: 14px;
}
}
Que 11. What is the purpose of the alt attribute in an tag?
Answer:
The alt
attribute provides alternative text for images, used by screen readers for accessibility and displayed if the image fails to load. It improves SEO and user experience.
<img src="logo.png" alt="Company logo">
Que 12. What is the difference between relative and absolute positioning in CSS?
Answer:
relative
: Positions relative to its normal position, respecting document flow.absolute
: Positions relative to the nearest positioned ancestor, removed from flow.
.relative { position: relative; top: 10px; }
.absolute { position: absolute; top: 10px; left: 10px; }
Que 13. How do you handle events in JavaScript?
Answer:
Use addEventListener
to attach event handlers to DOM elements, specifying the event type (e.g., click
) and a callback function.
document.querySelector('#myButton').addEventListener('click', () => {
console.log('Button clicked');
});
Que 14. What is the purpose of the z-index property in CSS?
Answer:z-index
controls the stacking order of positioned elements. Higher values place elements in front. It works with position: relative
, absolute
, or fixed
.
.element {
position: absolute;
z-index: 10; /* Appears above z-index: 5 */
}
Que 15. What is a JavaScript closure, and why is it useful?
Answer:
A closure is a function that retains access to its outer scope’s variables after execution. It’s useful for data privacy and creating reusable functions.
function counter() {
let count = 0;
return () => count++;
}
const myCounter = counter();
console.log(myCounter()); // 0
console.log(myCounter()); // 1
Que 16. How do you make a website responsive?
Answer:
Use relative units (%, vw, rem, em), media queries, and frameworks like Bootstrap. Design mobile-first, test across devices, and use Flexbox or Grid for adaptive layouts.
.container {
width: 100%;
max-width: 1200px;
}
Que 17. What is the difference between null and undefined in JavaScript?
Answer:
null
: Represents an intentional absence of a value.undefined
: Indicates a variable is declared but not assigned. Use===
to distinguish them.
let a; // undefined
let b = null; // null
console.log(a === b); // false
Que 18. What is the purpose of the <meta>
tag in HTML?
Answer:
The <meta>
tag provides metadata about the HTML document, like character encoding, viewport settings, or SEO details. It doesn’t display content.
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
Que 19. How do you include external CSS and JavaScript files in HTML?
Answer:
Use the <link>
tag for CSS and <script>
for JavaScript. Place CSS in <head>
and scripts at the end of <body>
for optimal loading.
<head>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<script src="script.js"></script>
</body>
Que 20. What is event bubbling in JavaScript?
Answer:
Event bubbling is when an event on an element propagates to its parent elements in the DOM tree. Use event.stopPropagation()
to prevent it.
document.querySelector('#child').addEventListener('click', (e) => {
e.stopPropagation();
console.log('Child clicked');
});
Que 21. What is the difference between flex and grid in CSS?
Answer:
Flexbox is one-dimensional, ideal for linear layouts (rows or columns). Grid is two-dimensional, suited for complex layouts with rows and columns. Use Flexbox for simpler alignments, Grid for structured layouts.
.container {
display: grid;
grid-template-columns: 1fr 1fr;
}
Que 22. How do you debug JavaScript code in a browser?
Answer:
Use browser DevTools (e.g., Chrome DevTools) to set breakpoints, inspect variables, and view console logs. Use console.log()
, debugger
statements, or tools like VS Code for debugging.
function test() {
console.log('Debugging');
debugger; // Pauses execution
}
Que 23. What is the purpose of the async attribute in a
Answer:
The async
attribute allows a script to load asynchronously, not blocking HTML parsing. It’s ideal for independent scripts but may cause out-of-order execution.
<script async src="script.js"></script>
Que 24. How do you style a button to look consistent across browsers?
Answer:
Reset default styles with appearance: none
, use consistent padding, borders, and fonts, and test with tools like BrowserStack. Use CSS frameworks for pre-tested styles.
button {
appearance: none;
padding: 10px 20px;
border: 1px solid #333;
}
Que 25. What is the difference between localStorage and sessionStorage in JavaScript?
Answer:localStorage
persists data across sessions until explicitly cleared. sessionStorage
persists only for the current session (tab). Both store key-value pairs.
localStorage.setItem('key', 'value');
sessionStorage.setItem('key', 'value');

Also check: Front End Developer Interview Questions for Experienced
Advanced Front End Developer Interview Questions for Freshers
Que 26. What is the purpose of the class attribute in HTML?
Answer:
The class
attribute assigns one or more class names to an HTML element, allowing CSS or JavaScript to target it for styling or manipulation. Multiple elements can share the same class.
<div class="container">Content</div>
<style>
.container { background: blue; }
</style>
Que 27. What is the difference between id and class in HTML?
Answer:id
uniquely identifies a single element, while class
can be applied to multiple elements. Use id
for specific elements and class
for reusable styles or behaviors.
<div id="unique" class="shared">Text</div>
Que 28. How do you select an element by its ID in JavaScript?
Answer:
Use document.getElementById()
to select an element by its unique ID, returning the element for manipulation.
const element = document.getElementById('unique');
element.textContent = 'Updated';
Que 29. What is the purpose of the for attribute in an HTML tag?
Answer:
The for
attribute links a <label>
to a form input by matching the input’s id
. Clicking the label focuses or activates the input, improving accessibility.
<label for="username">Username:</label>
<input id="username" type="text">
Que 30. How do you create a responsive image in HTML and CSS?
Answer:
Use the max-width: 100%
CSS rule to ensure images scale within their container. Use the srcset
attribute in <img>
for responsive image sources based on screen size.
<img src="image.jpg" srcset="image-2x.jpg 2x" alt="Responsive image">
<style>
img { max-width: 100%; height: auto; }
</style>
Que 31. What is the float property in CSS, and how does it work?
Answer:
The float
property positions an element to the left or right, allowing content to wrap around it. Common for layouts but often replaced by Flexbox or Grid.
.image { float: left; margin-right: 10px; }
Que 32. How do you clear a float in CSS?
Answer:
Use the clear
property or a clearfix hack to prevent elements from wrapping around floated elements. A common clearfix involves pseudo-elements.
.clearfix::after {
content: "";
display: block;
clear: both;
}
Que 33. What is the purpose of the data- attribute in HTML?
Answer:data-
attributes store custom data on HTML elements, accessible via JavaScript or CSS. They’re useful for storing metadata without affecting rendering.
<div data-info="123" id="myDiv"></div>
<script>
const div = document.getElementById('myDiv');
console.log(div.dataset.info); // 123
</script>
Que 34. What is the difference between script, script async, and script defer in HTML?
Answer:
<script>
: Blocks HTML parsing until executed.<script async>
: Loads asynchronously, executes immediately, may disrupt order.<script defer>
: Loads asynchronously, executes after HTML parsing, preserving order.
<script defer src="script.js"></script>
Que 35. How do you select multiple elements by class in JavaScript?
Answer:
Use document.querySelectorAll()
with a class selector to return a NodeList of elements with the specified class.
const elements = document.querySelectorAll('.item');
elements.forEach(el => el.style.color = 'blue');
Que 36. What is the purpose of the CSS position: sticky property?
Answer:position: sticky
keeps an element fixed relative to its nearest scrolling ancestor until it crosses a threshold, then scrolls normally. Useful for sticky headers.
.header {
position: sticky;
top: 0;
}
Que 37. How do you create a hyperlink in HTML?
Answer:
Use the <a>
tag with the href
attribute to define the destination URL. Add target="_blank"
to open in a new tab.
<a href="https://example.com" target="_blank">Visit Example</a>
Que 38. What is the ::before and ::after pseudo-elements in CSS?
Answer:::before
and ::after
insert content before or after an element’s content. They require the content
property and are useful for decorative elements.
.element::before {
content: "★";
color: gold;
}
Que 39. How do you prevent default behavior of an event in JavaScript?
Answer:
Use event.preventDefault()
to stop the default action of an event, such as preventing a form submission or link navigation.
document.querySelector('form').addEventListener('submit', (e) => {
e.preventDefault();
console.log('Form submission prevented');
});
Que 40. What is the purpose of the CSS overflow property?
Answer:
The overflow
property controls how content exceeding an element’s dimensions is handled. Options include visible
, hidden
, scroll
, or auto
.
.container {
overflow: auto;
height: 100px;
}
Que 41. How do you add comments in HTML, CSS, and JavaScript?
Answer:
- HTML:
<!-- Comment -->
- CSS:
/* Comment */
- JavaScript:
// Single-line
or/* Multi-line */
<!-- HTML comment -->
<style> /* CSS comment */ </style>
<script> // JS comment </script>
Que 42. What is the purpose of the tag in HTML?
Answer:
The <form>
tag groups input elements for data submission to a server, using attributes like action
(URL) and method
(GET/POST).
<form action="/submit" method="POST">
<input type="text" name="username">
<button type="submit">Submit</button>
</form>
Que 43. How do you style the first child of an element in CSS?
Answer:
Use the :first-child
pseudo-class to target the first child element of a parent.
li:first-child {
color: red;
}
Que 44. What is the difference between margin and padding in CSS?
Answer:margin
is the space outside an element, affecting its position relative to others. padding
is the space inside, between the content and border.
.box {
margin: 10px; /* Outside spacing */
padding: 10px; /* Inside spacing */
}
Que 45. How do you change the text content of an element using JavaScript?
Answer:
Use textContent
or innerText
to modify an element’s text. textContent
is preferred for better performance and security.
document.getElementById('myDiv').textContent = 'New text';
Que 46. What is the purpose of the viewport meta tag in HTML?
Answer:
The viewport
meta tag controls the layout on mobile devices, setting the width and initial scale for responsive design.
<meta name="viewport" content="width=device-width, initial-scale=1.0">
Que 47. How do you create a CSS animation?
Answer:
Use @keyframes
to define animation steps and apply with the animation
property, specifying name, duration, and timing.
@keyframes slide {
from { transform: translateX(0); }
to { transform: translateX(100px); }
}
.element {
animation: slide 2s ease-in-out;
}
Que 48. What is the difference between
and in HTML?
Answer:<div>
is a generic container with no semantic meaning. <section>
is a semantic element representing a thematic grouping of content, improving accessibility and SEO.
<section>
<div>Content</div>
</section>
Que 49. How do you toggle a class on an element in JavaScript?
Answer:
Use classList.toggle()
to add or remove a class from an element dynamically.
document.getElementById('myDiv').classList.toggle('active');
Que 50. What is the purpose of the CSS box-sizing property?
Answer:box-sizing
defines how width and height are calculated. content-box
includes only content, while border-box
includes padding and border, simplifying layout calculations.
* {
box-sizing: border-box;
}
Conclusion
We’ve shared all the essential questions in our Front End Developer Interview Questions for Freshers guide above. This complete resource includes interview questions for new graduates, covering both simple and advanced topics that hiring managers commonly ask about. The front end development field is moving fast with modern frameworks, mobile-first design, and accessibility standards becoming essential requirements for entry-level jobs.
These Front End Developer Interview Questions for Freshers give you the solid foundation you need for your job search, from basic HTML structure to interactive JavaScript features. With good preparation using these Front End Developer Interview Questions for Freshers and knowledge of current web development trends, you’ll be ready to start your front end development career successfully.
More Interview Guides: