JIYIK CN >

Current Location:Home > Learning > WEB FRONT-END > CSS >

CSS wrap text around image

Author:JIYIK Last Updated:2025/04/19 Views:

CSS allows you to wrap text around an image, which is a great way to create visually appealing and easy to read layouts in HTML, ultimately improving the readability of your content. You can set it to wrap around the left or right side of the image, or you can set it to wrap around the top or bottom of the image.


CSS wrap text around image

There are a number of ways to wrap text around an image in HTML. The most typical way is to use the align attribute.

We can use the align attribute to specify where we want to insert an image. For example, we can use the align attribute to center an image within a paragraph of text.

Using CSS, you have full control to wrap text around images accordingly. The text will wrap around the image by default to be flush with the left or right edge of the image.

However, you can use the CSS float property to control how text wraps around an image.

{
    float: left;
}

If you set the float property to left, the image will float to the left of the text and the text will wrap around the image. If you set the float property to right, the image will float to the right of the text and the text will wrap around the image.

You can also use the CSS clear property to control how text wraps around images.

If you set the clear property to left, the image will float to the left of the text and the text will not wrap around the image. If you set the clear property to right, the image will float to the right of the text and the text will not wrap around the image.

{
    clear: left;
}

You can also use the CSS overflow property to control how text wraps around images. If you set the overflow property to hidden, the image will float to the left or right of the text and the text will not wrap around the image.

{
    overflow: auto;
}

Finally, you can use the CSS padding property to control the space between the image and the text.

If you set the padding property to a value of 0, the image will be flush with the text. If you set the padding property to a value of 10px, there will be 10px of space between the image and the text.

{
    padding-top: 50px;
    padding-right: 30px;
    padding-bottom: 50px;
    padding-left: 80px;
}

Sample code:

<!DOCTYPE html>
<html>
    <head>
        <title>
            Wrapping an Image with the text
        </title>

        <style>
            body {
                margin: 20px;
                text-align: center;
            }

            h1 {
                color: green;
            }

            img {
                float: left;
                margin: 10px;
                padding-bottom: 2px;
                width: 250px;
            }

            p {
                text-align: justify;
                font-size: 25px;
            }
        </style>
    </head>
    <body>
        <h1>Wrap Text Around Image</h1>
        <b>
            The output of wrapping text around an image
        </b>
        <div class="square">
            <div>
                <img src="replaceYourImageHere.jpeg" alt="Longtail boat in Thailand" />
            </div>

            <p>
                There are a few different ways to wrap text around images in HTML; the most typical way is to use the `align` attribute. You can utilize the align attribute to specify the image position where you want to insert it.
                For instance, you can utilize the `align` attribute to center an image within a paragraph of text. With CSS, you are in full control to wrap text around an image accordingly. The text will default wrap around an image to flush
                with the image's left or right edge. However, you can use the CSS `float` property to control how text wraps around an image.
            </p>
        </div>
    </body>
</html>

Summarize

Surrounding images with text can also help improve the usability of your website or blog. When there is a lot of text on a page, it can be difficult to read if the image is in the middle of the text, but using images between the text can improve readability and comprehension.

For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.

Article URL:

Related Articles

Overriding Bootstrap CSS

Publish Date:2025/04/19 Views:80 Category:CSS

This article introduces the famous CSS UI framework Bootstrap. We will discuss the process of overriding Bootstrap CSS with custom styles. Bootstrap Overview Using Bootstrap CSS makes it quicker and easier to create responsive websites than

Applying multiple transformations in CSS

Publish Date:2025/04/19 Views:143 Category:CSS

CSS transforms are a powerful but underutilized way to add animation effects to elements. However, it can be tricky to get the desired results when applying multiple transformations at once; for example, we want elements to transform in syn

Styling input and submit buttons using CSS

Publish Date:2025/04/19 Views:193 Category:CSS

A submit button is a button used to submit data into a form. It is usually placed at the end of the form after all other fields are filled in. When you click the submit button, the form is transferred to the server for processing. The synta

Creating background image gradients using CSS

Publish Date:2025/04/19 Views:164 Category:CSS

A background image gradient is a gradual transition from one color to another. Background image gradients can be created using multiple colors, but they are usually most effective when using a limited color palette. This article will teach

Stretchable background images using CSS

Publish Date:2025/04/19 Views:82 Category:CSS

This short article is about styling HTML pages using CSS, focusing on styling background images of any HTML element. CSS styles on the web page There are a number of ways to use CSS on your web pages: Inline CSS: Inline CSS means that you u

Gradient backgrounds in CSS

Publish Date:2025/04/19 Views:148 Category:CSS

This simple guide is about the use of CSS properties that can be used to define a rainbow-like gradient background for an HTML element. CSS Gradients We can use CSS gradients to display a seamless transition between two or more specified co

First Of Class in CSS

Publish Date:2025/04/19 Views:158 Category:CSS

CSS :first-of-type selectors are used to select the first element of its type within a group of elements. For example, if you have a group of paragraphs, :first-of-type the selector will select the first paragraph in the group. This selecto

Bringing an element to the front using CSS

Publish Date:2025/04/19 Views:111 Category:CSS

If an element is not set to cover the entire display area, you can z-index bring it to the front using the property. z-index The property determines the stacking order of elements on the page. z-index The higher element is stacked z-index o

Changing the color of SVG elements in HTML using CSS

Publish Date:2025/04/19 Views:83 Category:CSS

This simple guide is all about using SVG in an HTML document and how we can customize it to change its color using CSS properties. First, we will take a brief look at SVG in HTML. Introduction to SVG Similar to XHTML, SVG is an XML language

Scan to Read All Tech Tutorials

Social Media
  • https://www.github.com/onmpw
  • qq:1244347461

Recommended

Tags

Scan the Code
Easier Access Tutorial