Skip to content

HTML/CSS

What is HTML5? Differences between HTML4 and HTML5?

HTML5 is the latest version of the Hypertext Markup Language (HTML), which is used to structure and present content on the web. It introduces new features and improvements over its predecessor version. Some key differences between HTML4 and HTML5 include:

  1. New Semantic Elements: HTML5 introduces new semantic elements like <header>, <footer>, <article>, <section>, and <nav> to provide better structure and meaning to web content.
  2. Multimedia Support: HTML5 includes native support for audio and video elements (<audio> and <video>) without the need for third-party plugins like Flash.
  3. Canvas Element: HTML5 introduces the <canvas> element, which allows for dynamic, scriptable rendering of 2D shapes and images.
  4. Form Enhancements: HTML5 adds new input types (e.g., email, date, number) and attributes (e.g., placeholder, required) to improve form usability and validation.
  5. Improved Accessibility: HTML5 includes features that enhance accessibility for users with disabilities, such as ARIA (Accessible Rich Internet Applications) roles and attributes.

Overall, HTML5 represents a significant advancement in web development, providing developers with more tools and capabilities to create rich, interactive, and user-friendly web experiences.

What is the difference between an id and a class in HTML/CSS?

An id is a unique identifier for a single HTML element. A class is a reusable identifier that can be applied to multiple elements.

In CSS, an id is selected using the # symbol, while a class is selected using the . symbol.

What is CSS

CSS (Cascading Style Sheets) is a stylesheet language used to describe the presentation of a document written in HTML or XML. It allows developers to separate content from design, making it easier to maintain and update styles across a website.

Can you explain the box model in CSS?

The CSS box model describes the rectangular boxes generated for elements in the DOM. The box model is composed of the following layers:

  1. Content: The innermost part, where text and images appear.

  2. Padding: The space between the content and the border.

  3. Border: The outer edge of the padding, surrounding the element.

  4. Margin: The space outside the border, separating the element from others.

What is the difference between inline, inline-block, and block elements?

In CSS, the difference between inline, inline-block, and block elements is on the way they’re rendered in the web page:

Inline: Inline elements don’t have a width or height. They don’t start on a new line and take up only the width that’s required (based on their content). Examples: <span>, <a>.

Inline-block: Do not start on a new line, but allow you to set height and width. Example: <img>.

Block: Elements start on a new line, taking up the full width available by default. Their width and height can be set. Examples: <div>, <p>.

What is the difference between the em and rem units?

They’re both relative units of measurement, however, they’re relative to different things:

“em” units are relative to the font size of their parent element. So if the parent element has a font size of 20px, then setting a “2em” font size, would equal to 40px.

“rem” units are “root em”, which means they’re relative to the web page’s root element (the <html> element).

Flexbox vs Grid vs Box Layout

Flexbox is a one-dimensional layout model that arranges items in a row or a column. It’s best used for smaller layout changes, like aligning items in a navigation bar or a footer.

Grid is a two-dimensional layout model that arranges items in rows and columns. It’s best used for larger layout changes, like creating a responsive grid layout for a website.

Box Layout is the default layout model in CSS. It’s based on the box model, where each element is a rectangular box. It’s best used for simple layouts, like centering an element on the page.

Can you explain CSS specificity and how it works?

CSS specificity is a set of rules that determine which CSS rule is applied to an element when multiple rules could apply. It is calculated based on the types of selectors used in the CSS rules. The specificity hierarchy is as follows (from highest to lowest):

  1. Inline styles (e.g., style="color: red;") - specificity value of 1000
  2. IDs (e.g., #header) - specificity value of 100
  3. Classes, attributes, and pseudo-classes (e.g., .nav, [type ="text"], :hover) - specificity value of 10
  4. Elements and pseudo-elements (e.g., div, p, ::before) - specificity value of 1
  5. Universal selector (*), combinators (+, >, ~, ), and negation pseudo-class (:not()) - specificity value of 0

When multiple CSS rules apply to the same element, the rule with the highest specificity takes precedence. If two rules have the same specificity, the one that appears last in the CSS file will be applied.

What are media queries?

Media queries are a CSS technique used to apply different styles to a web page based on the characteristics of the device or viewport, such as screen size, resolution, orientation, and more. They enable responsive web design, allowing websites to adapt their layout and appearance to provide an optimal user experience across various devices, including desktops, tablets, and smartphones.

Explain some of the pros and cons for CSS animations versus JavaScript animations.

Use CSS animations for simpler “one-shot” transitions, like toggling UI element states. Use JavaScript animations when you want advanced effects like bouncing, stop, pause, rewind, or slowing down. If you choose to animate with JavaScript, use the Web Animations API or a modern framework you’re comfortable with.

CSS animations are generally more performant than JavaScript animations because they can be optimized by the browser's rendering engine with GPU acceleration.

"Css Selector: ~, >, +, #, ."

div p: Selects all <p> elements inside <div> elements p.intro: Selects all <p> elements with class="intro" #firstname: Selects the element with id="firstname" .name1.name2: Selects elements with both name1 and name2 classes .name1 .name2: Selects descendants with name2 under an element with name1 div > p: Selects <p> elements whose parent is a <div> div + p: Selects the first <p> immediately after a <div> p ~ ul: Selects all <ul> elements placed after a <p>

Reference: CSS Selectors Reference

What is CSS-in-JS?

CSS-in-JS is a styling approach where CSS is written using JavaScript. It allows developers to define styles within JavaScript files, often using libraries like styled-components or Emotion. This approach enables dynamic styling based on component state, props, or themes, and promotes component-based architecture by encapsulating styles with the components they belong to.

tailwindcss vs Bootstrap

Tailwind CSS is a utility-first CSS framework that provides low-level utility classes to build custom designs without writing custom CSS. It allows developers to compose styles directly in their HTML or JSX, promoting a more atomic approach to styling. Bootstrap is a component-based CSS framework that provides pre-designed UI components and layout utilities. It offers a set of ready-to-use styles and components, making it easier to create responsive and consistent designs quickly.

What is Sass?

Sass is a CSS preprocessor that extends CSS with features like variables, nested rules, mixins, and functions. It allows developers to write more maintainable and reusable stylesheets. Sass files are typically written in .scss or .sass formats and need to be compiled into standard CSS before being used in a web project.

We can compile Sass using build tools like Gulp or Webpack.

What is PostCSS?

PostCSS is a tool for transforming CSS with JavaScript plugins. It allows developers to use various plugins to automate tasks such as autoprefixing, minification, linting, and adding future CSS features that may not yet be supported by all browsers. PostCSS processes CSS files and applies the specified transformations, resulting in optimized and compatible stylesheets for web projects.

PostCSS is used over traditional CSS preprocessors like Sass or LESS when developers want more flexibility in choosing specific plugins for their workflow, rather than relying on a single preprocessor's features.

What is Accessibility?

Accessibility refers to the design and development of websites, applications, and digital content in a way that ensures they can be used by people with disabilities. The goal of accessibility is to create an inclusive digital environment where everyone, regardless of their abilities, can access and interact with online content effectively. This involves following best practices, guidelines (such as the Web Content Accessibility Guidelines - WCAG), and using semantic HTML, proper ARIA (Accessible Rich Internet Applications) attributes, and ensuring keyboard navigability, among other techniques.

Some important interface considerations for Accessibility

Some important interface considerations for Accessibility include:

  1. Keyboard Accessibility: Ensure that all interactive elements can be accessed and operated using a keyboard alone.
  2. Screen Reader Compatibility: Use semantic HTML and ARIA roles to ensure that screen readers can accurately interpret and convey the content.
  3. Color Contrast: Ensure sufficient contrast between text and background colors to make content readable for users with visual impairments.
  4. Text Alternatives: Provide alternative text for images, icons, and other non-text content to convey their meaning to users who cannot see them.
  5. Responsive Design: Ensure that the interface is usable on various devices and screen sizes, including mobile devices.

What are Landmark regions?

Landmark regions are specific areas of a web page that are defined using ARIA (Accessible Rich Internet Applications) roles to help users with assistive technologies navigate the content more easily. These regions provide a way to identify and label different sections of a web page, such as the main content, navigation, header, footer, and complementary content. HTML5 provides several semantic elements that automatically define landmark regions, such as <header>, <nav>, <main>, <aside>, and <footer>. Additionally, ARIA roles like role="banner", role="navigation", role="main", role="complementary", and role="contentinfo" can be used to explicitly define these regions. See here for Common landmark regions

What are structural roles?

ARIA provides a set of roles that convey the accessibility semantics of structures on a page. These roles express the meaning that is conveyed by the layout and appearance of elements that organize and structure content, such as headings, lists, and tables.

See here for a list of ARIA structural roles.

List some common Accessibility patterns

Some common accessibility patterns include: https://www.w3.org/WAI/ARIA/apg/patterns/

PatternARIA RolesKeyboard InteractionHTML Structure
Accordionbutton, regionEnter or Space to toggle sections, Tab to navigate between headersUse <button> for headers and <div> or <section> for content panels
AlertalertAutomatically announced by screen readersUse a <div> or <section> with role="alert" for important messages
Alert DialogalertdialogTab to navigate, Escape to closeUse a <div> or <section> with role="alertdialog" for modal dialogs
Breadcrumbnavigation, list, listitemTab to navigate through breadcrumb linksUse a <nav> element with an ordered list <ol> for breadcrumb items
ButtonbuttonEnter or Space to activateUse a <button> element or a <div>/<span> with role="button" and appropriate keyboard event handlers
Carouselregion, button, tabpanelArrow Left/Right to navigate slides, Tab to focus on controlsUse a <div> or <section> for the carousel container and <button> elements for navigation controls
CheckboxcheckboxSpace to toggle, Tab to navigateUse an <input type="checkbox"> element
Comboboxcombobox, listbox, optionArrow Down/Up to navigate options, Enter to selectUse an <input> for the text field and a <ul> or <div> for the dropdown list
Dialog (Modal)dialogTab to navigate, Escape to closeUse a <div> or <section> with role="dialog" for modal dialogs
Disclosurebutton, regionEnter or Space to toggle visibility, Tab to navigateUse a <button> for the trigger and a <div> or <section> for the content
Feedfeed, articleTab to navigate through articlesUse a <div> or <section> with role="feed" for the feed container and <article> elements for individual posts
Gridgrid, row, gridcellArrow Keys to navigate cells, Tab to move between rowsUse a <div> or <section> with role="grid" for the grid container and nested <div> or <span> elements for rows and cells
Landmark Regionsbanner, navigation, main, complementary, contentinfoLandmark Navigation shortcuts in screen readersUse semantic HTML5 elements like <header>, <nav>, <main>, <aside>, and <footer> or corresponding ARIA roles
LinklinkEnter to activate, Tab to navigateUse an <a> element for links
Listboxlistbox, optionArrow Down/Up to navigate options, Enter to selectUse a <ul> or <div> for the listbox container
Menu and Menubarmenu, menuitem, menubarArrow Keys to navigate menu items, Enter to activateUse a <nav> element with nested <ul> and <li> elements for menu items
Menu Buttonbutton, menu, menuitemEnter or Space to open/close menu, Arrow Keys to navigateUse a <button> for the trigger and a <ul> or <div> for the menu
MetermeterTab to navigateUse a <meter> element for displaying a scalar measurement
Radio Groupradiogroup, radioArrow Keys to navigate options, Space to selectUse <input type="radio"> elements grouped within a container
SlidersliderArrow Left/Right to adjust value, Tab to navigateUse a <div> or <input type="range"> for the slider control
Slider (Multi-thumb)sliderArrow Left/Right to adjust value, Tab to navigateUse a <div> or <input type="range"> for the slider control with multiple thumbs
SpinbuttonspinbuttonArrow Up/Down to increment/decrement value, Tab to navigateUse an <input type="number"> or a custom control with appropriate ARIA attributes
SwitchswitchSpace to toggle, Tab to navigateUse a <button> or a custom control with role="switch"
Tabletable, row, columnheader, rowheader, cellTab to navigate cells, Arrow Keys for cell navigationUse <table>, <tr>, <th>, and <td> elements for tabular data
Tabstablist, tab, tabpanelArrow Left/Right to navigate tabs, Tab to focus on tab panelsUse a <div> or <section> for the tab container, <button> elements for tabs, and <div> or <section> for tab panels
Toolbartoolbar, buttonTab to navigate buttons, Enter or Space to activateUse a <div> or <section> with role="toolbar" for the toolbar container and <button> elements for individual tools
TooltiptooltipTab to focus on the element with the tooltip, Escape to dismissUse a <div> or <span> with role="tooltip" for the tooltip content
Tree Viewtree, treeitem, groupArrow Keys to navigate tree items, Enter or Space to expand/collapseUse a <div> or <section> with role="tree" for the tree container and nested <div> or <span> elements for tree items and groups
Tree Gridtreegrid, row, gridcell, treeitemArrow Keys to navigate cells and tree items, Enter or Space to expand/collapseUse a <div> or <section> with role="treegrid" for the tree grid container and nested <div> or <span> elements for rows, cells, and tree items
Window SplitterseparatorArrow Keys to adjust the splitter position, Tab to navigateUse a <div> or <section> with role="separator" for the splitter control

Software Engineer Interview Preparation