<marquee>

HTML <marquee> Tag

The <marquee> is a non-standard HTML tag which was used to create a scrolling text or an image. It was used to make the text or image scroll horizontally across or vertically down the web page. Because of its usability problems it was often compared with Netscape’s blink element.

The <marquee> element is a deprecated HTML tag. If you use it, your pages or apps may be broken.

Alternatives of the HTML <marquee> tag

Alternatives of the HTML <marquee> tag

As it was said above, the HTML <marquee> tag is deprecated, and the developers often avoid using it. Nowadays, you can achieve the same result with the help of CSS and Javascript. Read our snippet to learn more about this method.

Syntax

Syntax (语法)

The <marquee> tag comes in pairs. The content is written between the opening (<marquee>) and closing (</marquee>) tags.

Example of using HTML <marquee> tag:

<!DOCTYPE html>
<html>
 <head>
   <title>Title of the document</title>
   <style>
     marquee{
     font-size: 30px;
     font-weight: 800;
     color: #8ebf42;
     font-family: sans-serif;
     }
   </style>
 </head>
 <body>
   <marquee>A scrolling text created with HTML Marquee element.</marquee>
 </body>
</html>

Use direction attribute of <marquee> element to change the direction of the text/image. See another example where the text scrolls from up to down.

Example of a scrolling text:

<!DOCTYPE html>
<html>
 <head>
   <title>Title of the document</title>
 </head>
 <body>
   <marquee direction="down">A scrolling text created with HTML Marquee element.</marquee>
 </body>
</html>

Now let’s see an example of using <marquee> element for setting a scrolling image:

Example of a scrolling image:

<!DOCTYPE html>
<html>
 <head>
   <title>Title of the document</title>
 </head>
 <body>
    <marquee behavior="scroll" direction="up">
     <img src="/uploads/media/default/0001/01/0710cad7a1017902166203def268a0df2a5fd545.png" width="190" height="45" alt="w3cdoc" />
   </marquee>
 </body>
</html>

Use CSS width and background-color properties to style the <marquee> element.

Example of creating a scrolling text with HTML <marquee> tag:

<!DOCTYPE html>
<html>
 <head>
   <title>Title of the document</title>
 </head>
 <body>
   <style> 
     marquee {
       width: 100%;
       padding: 10px 0;
       background-color: lightblue;
     }
   </style>
   <marquee direction="scroll">This scrolling text is created with HTML Marquee element and styled with CSS properties.</marquee>
 </body>
</html>

Attributes

Attributes (属性)

The following attributes can be used to adjust the appearance of the <marquee> element.

AttributeValueDescription
behaviorscrollslidealternateDefines the scrolling type.
bgcolorrgb(x,x,x)#xxxxxxcolornameIs used to give a background color.
directionupdownleftrightSets the direction for the scrolling content.
heightpixels%Defines the marquee’s height.
hspacepixelsDefines horizontal space around the marquee.
loopnumberDefines how many times the content will scroll. If we don’t define this, the content will scroll forever.
scrollamountnumberDefines the scrolling amount at each interval in pixels. Default value is 6.
scrolldelaysecondsDefines how long delay will be between each jump. The default value is 85 and smaller amounts than 60 will be ignored.
truespeedsecondsIs used to delay the scroll lesser than 60.
vspacepixelsDefines vertical space around the marquee.
widthpixels%Defines the marquee’s width.

The <marquee> tag also supports the the Global attributes and the Event Attributes.

How to style <marquee> tag? Common properties to alter the visual weight/emphasis/size of text in <marquee> tag:

CSS font-style property sets the style of the font. normal | italic | oblique | initial | inherit. CSS font-family property specifies a prioritized list of one or more font family names and/or generic family names for the selected element. CSS font-size property sets the size of the font. CSS font-weight property defines whether the font should be bold or thick. CSS text-transform property controls text case and capitalization. CSS text-decoration property specifies the decoration added to text, and is a shorthand property for text-decoration-line, text-decoration-color, text-decoration-style.

Coloring text in <marquee> tag:

CSS color property describes the color of the text content and text decorations. CSS background-color property sets the background color of an element.

Text layout styles for <marquee> tag:

CSS text-indent property specifies the indentation of the first line in a text block. CSS text-overflow property specifies how overflowed content that is not displayed should be signalled to the user. CSS white-space property specifies how white-space inside an element is handled. CSS word-break property specifies where the lines should be broken.

Other properties worth looking at for <marquee> tag:

CSS text-shadow property adds shadow to text. CSS text-align-last property sets the alignment of the last line of the text. CSS line-height property specifies the height of a line. CSS letter-spacing property defines the spaces between letters/characters in a text. CSS word-spacing property sets the spacing between words.



请遵守《互联网环境法规》文明发言,欢迎讨论问题
扫码反馈

扫一扫,反馈当前页面

咨询反馈
扫码关注
返回顶部