Coding Schools


 
Python | C Sharp | Azure AI | HTML | JavaScript | CSS | SQL Server
Basic Structure of HTML
HTML 5 Features
IFrame in HTML
HTML - div and span tags
HTML - marquee element
HTML - List elements
HTML - paragraph element
HTML - table elements

HTML - marquee element



The <marquee> element in HTML is used to create scrolling text or images across the screen. It was once a popular way to add dynamic content to web pages, but it is now considered obsolete and discouraged from use. Modern web development practices favor CSS and JavaScript for creating animations and scrolling effects.

Basic Syntax

The basic syntax for the <marquee> element is as follows:

html
<marquee>Scrolling text here</marquee>

Attributes

The <marquee> element has several attributes that control its behavior:

  • direction: Specifies the direction of the scroll. Possible values are left, right, up, and down.

    html
    <marquee direction="left">Scrolling left</marquee>
    
  • behavior: Defines the scrolling behavior. Possible values are scroll, slide, and alternate.

    html
    <marquee behavior="alternate">Alternating text</marquee>
    
  • scrollamount: Sets the speed of the scroll, measured in pixels.

    html
    <marquee scrollamount="10">Fast scrolling text</marquee>
    
  • scrolldelay: Sets the delay between each scroll movement, measured in milliseconds.

    html
    <marquee scrolldelay="100">Slow scrolling text</marquee>
    
  • loop: Specifies the number of times the marquee should loop. The value can be a number or infinite for continuous scrolling.

    html
    <marquee loop="3">Scrolling text three times</marquee>
    
  • bgcolor: Sets the background color of the marquee.

    html
    <marquee bgcolor="#ffcc00">Scrolling text with background color</marquee>
    

Example

Here's an example that combines several attributes:

html
<marquee direction="left" behavior="scroll" scrollamount="5" scrolldelay="50" loop="infinite" bgcolor="#f0f0f0">
    Welcome to our website!
</marquee>

Alternatives to <marquee>

As the <marquee> element is obsolete, modern web development recommends using CSS and JavaScript for similar effects. Here' a simple example using CSS animations:

HTML:

html
<div class="marquee">
    <p>Welcome to our website!</p>
</div>

CSS:

css
.marquee {
    width: 100%;
    overflow: hidden;
    white-space: nowrap;
    box-sizing: border-box;
}

.marquee p {
    display: inline-block;
    padding-left: 100%;
    animation: marquee 10s linear infinite;
}

@keyframes marquee {
    0% { transform: translateX(0); }
    100% { transform: translateX(-100%); }
}

This CSS example achieves a similar scrolling effect without relying on the deprecated <marquee> element.

If you have any specific scenarios or need further help with animations or scrolling effects, feel free to ask!




All rights reserved | Privacy Policy | Sitemap