The default body margin in HTML is 8px on all sides. This margin is applied by the browser's user-agent stylesheet, creating a small space between the page content and the viewport edges. Understanding and controlling this default margin is essential for creating precise web layouts. Default Margin in HTML All modern browsers apply a default margin of 8px to the element. This prevents content from touching the browser window edges, providing better readability. The margin appears as white space around your content. Example − Default 8px Margin Following example shows how the default margin creates ... Read More
The HTML DOM storage event is triggered when changes occur in the browser's storage areas (localStorage or sessionStorage). This event fires when another window, tab, or frame modifies the storage, making it useful for synchronizing data across multiple windows of the same origin. The storage event is particularly valuable for creating real-time communication between different browser windows or tabs without requiring server-side communication. It only triggers when the storage change originates from a different browsing context, not from the current window itself. Syntax Following is the syntax for adding a storage event listener − window.addEventListener("storage", ... Read More
Tables can be used to create structured and organized forms in HTML. Using tables for form layout provides better alignment and visual organization of form elements, making forms more readable and professional-looking. Let us first understand how to create a basic form and then see how tables enhance form structure. Basic Form Structure The tag creates a container for form elements. Form controls like input fields, buttons, and labels are placed within this container to collect user data. Syntax Example − Simple Form Following example ... Read More
The HTML DOM Storage getItem() method is used to retrieve the value of a specific item from web storage by providing its key name. If the key exists, it returns the stored value as a string. If the key doesn't exist, it returns null. The getItem() method works with both localStorage (persistent storage) and sessionStorage (temporary storage that expires when the tab closes). Syntax Following is the syntax for the Storage getItem() method − localStorage.getItem(keyname); OR sessionStorage.getItem(keyname); Parameters The getItem() method accepts a single parameter − ... Read More
To apply CSS to iframe is a straightforward process using any of the three methods of adding CSS to HTML documents. An iframe element can be styled just like any other HTML element using inline, internal, or external CSS. Styling iframes is commonly needed to control their appearance, set dimensions, add borders, and ensure they integrate seamlessly with your page design. Each CSS approach offers different advantages depending on your specific requirements. Syntax The basic syntax for styling an iframe with CSS − iframe { /* CSS properties */ ... Read More
The input number type in HTML allows users to enter numeric values, but by default it accepts both positive and negative numbers. To restrict input to only positive numbers, we need to combine HTML attributes with JavaScript validation techniques. The element provides several attributes for controlling numeric input: min, max, step, and value. However, the min attribute alone only restricts the spinner controls and form validation − users can still manually type negative numbers. Syntax Basic syntax for a number input with minimum value restriction − For complete positive-only restriction with ... Read More
The HTML ondblclick attribute is an event handler that triggers when a user double-clicks on an HTML element. This attribute allows you to execute JavaScript code in response to the double-click mouse event. Syntax Following is the syntax for using the ondblclick attribute − Content Parameters script − The JavaScript code to execute when the element is double-clicked. This can be a function call or inline JavaScript statements. Example − Button Double-Click Following example demonstrates the ondblclick event attribute with a button element − ... Read More
The HTML DOM Object form property returns a reference to the form element that contains an element. This property is read-only and provides a way to access the parent form from within JavaScript when working with object elements. Syntax Following is the syntax for accessing the form property − ObjectElement.form Return Value The property returns a reference to the HTMLFormElement that contains the object, or null if the object element is not enclosed within a form. Example Following example demonstrates how to use the Object form property to get a ... Read More
Moving images in HTML can be achieved through various methods, from traditional HTML tags to modern CSS properties and JavaScript. An image is added to a web page using the HTML tag, which is a self-closing element that simply includes attributes. While the HTML tag was previously used to create scrolling images, it is now deprecated in HTML5. Modern web development favors CSS properties and JavaScript for more precise control over image positioning and movement. Syntax The basic syntax for adding an image in HTML is − To move images, ... Read More
The tag in HTML creates an input control that accepts user input. The type attribute determines the kind of input field displayed, such as text fields, checkboxes, buttons, or file uploads. When working with file uploads, you often need to restrict the allowed file types to only accept image files. The element by default accepts all file types, but you can limit it to images using the accept attribute or JavaScript validation. This ensures users can only select image files from their device. Syntax Following is the basic syntax for file input − ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Economics & Finance