• HTML
  • React
  • Knowledge Base
  • HTML
  • React
  • Knowledge Base
  • HTML Tutorial
  • HTML Styles – CSS
  • Link to an Email Address
  • HTML Introduction
  • HTML Editors
  • HTML Basic Examples
  • HTML Elements
  • HTML Attributes
  • HTML Headings
  • HTML Paragraphs
  • HTML Styles
  • HTML Text Formatting
  • HTML Quotation and Citation Elements
  • HTML Comments
  • HTML Colors
  • HTML RGB and RGBA Colors
  • HTML HEX Colors
  • HTML HSL and HSLA Colors
  • CSS Colors, Fonts and Sizes
  • CSS Padding
  • CSS Border
  • CSS Margin
  • Link to External CSS
  • HTML Style Tags
  • HTML Links
  • HTML Links – The target Attribute
  • Absolute URLs vs. Relative URLs
  • HTML Links – Use an Image as a Link
  • Button as a Link
  • Link Titles
  • Absolute URLs and Relative URLs
  • HTML Link Tags
  • HTML Links – Different Colors
  • Link Buttons
  • HTML Links – Create Bookmarks
  • The alt Attribute
  • HTML Images
  • Image Size – Width and Height
  • Image Width and Height, or Style
  • Images in Another Folder
  • HTML Images on Another Server/Website
  • HTML Animated Images
  • Image as a Link
  • Image Floating
  • Common Image Formats
  • HTML Image Tags
  • The render Method

Image Floating

3 views 0

Written by admin
April 15, 2023

You can use CSS to float an image to the left or right of the text in HTML. To do this, you can use the float property and set it to left or right.

Here’s an example of how to float an image to the left of the text:

<div>
  <img src="example.jpg" alt="Example Image" style="float: left; margin-right: 10px;">
  <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum sed elit ut libero ullamcorper finibus. Sed eget augue ut ex dapibus tempus.</p>
</div>

In this example, the <img> tag is wrapped in a <div> tag to group the image and text together. The float property is set to left to float the image to the left of the text, and the margin-right property is used to add a small gap between the image and text.

You can also float an image to the right by setting the float property to right, like this:

<div>
  <img src="example.jpg" alt="Example Image" style="float: right; margin-left: 10px;">
  <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum sed elit ut libero ullamcorper finibus. Sed eget augue ut ex dapibus tempus.</p>
</div>

In this example, the float property is set to right and the margin-left property is used to add a small gap between the image and text.

Note that when you float an image, the surrounding text will wrap around it. If the image is larger than the width of its container, you may need to adjust the container’s width or use other CSS properties to control the layout.

Was this helpful?

Yes  No
Related Articles
  • The render Method
  • HTML Image Tags
  • Common Image Formats
  • Image as a Link
  • HTML Animated Images
  • HTML Images on Another Server/Website

Didn't find your answer? Contact Us

Leave A Comment Cancel reply

Previously
Image as a Link
Up Next
Common Image Formats
Copyright 2022 k-window. All Rights Reserved