HTML Image Border, Align, Padding and Margin
HTML provides several ways to add borders and align images on a webpage. Following section will explore some common techniques for adding borders and aligning images in HTML.
Adding a Border to an Image
To add a border to an image in HTML, you can use the "border" attribute in the <img> tag. The "border" attribute specifies the width of the border around the image, in pixels.
In this example, added a border of 1 pixel around the image.
You can also use CSS to add borders to images.
In this example, used CSS to add a 1 pixel solid black border around the image.
Removing the Border from an Image
To remove the border from an image in HTML, you can set the "border" attribute to 0 or remove the attribute altogether.
In this example, set the "border" attribute to 0 to remove the border from the image.
In this example, removed the "border" attribute altogether, which also removes the border from the image.
Aligning an Image
To align an image in HTML, you can use the "align" attribute in the <img> tag. The "align" attribute specifies the horizontal alignment of the image with respect to the surrounding content.
In this example, aligned the image to the center of the webpage.
You can also use CSS to align images.
In this example, used CSS to center the image horizontally by setting the "display" property to "block" and the "margin" property to "0 auto".
You can also align images to the left or right of the surrounding text by setting the "align" attribute to "left" or "right".
In this example, aligned the image to the left of the surrounding text.
Adding Padding and Margin to an Image
To add padding or margin to an image in HTML, you can use CSS.
In this example, added 10 pixels of padding and margin around the image.
Making an Image Responsive
To make an image responsive in HTML, you can use CSS. One common technique is to set the "max-width" property of the image to 100%, which makes the image resize proportionally with the width of the viewport.
In this example, made the image responsive by setting the "max-width" property to 100% and the "height" property to "auto". This ensures that the image resizes proportionally
Conclusion:
HTML offers various attributes such as border, align, padding, and margin to customize the display and spacing of images on a webpage. Border defines the thickness and style of the image border, align determines the horizontal alignment of the image, and padding and margin specify the spacing around the image.