Movatterモバイル変換


[0]ホーム

URL:


Menu
×
See More 
Sign In
+1 Get Certified Upgrade For Teachers Spaces Get Certified Upgrade For Teachers Spaces
   ❮     
     ❯   

CSS Tutorial

CSS HOMECSS IntroductionCSS SyntaxCSS SelectorsCSS How ToCSS CommentsCSS ErrorsCSS ColorsCSS BackgroundsCSS BordersCSS MarginsCSS PaddingCSS Height/WidthCSS Box ModelCSS OutlineCSS TextCSS FontsCSS IconsCSS LinksCSS ListsCSS TablesCSS DisplayCSS Max-widthCSS PositionCSS Z-indexCSS OverflowCSS FloatCSS Inline-blockCSS AlignCSS CombinatorsCSS Pseudo-classesCSS Pseudo-elementsCSS OpacityCSS Navigation BarsCSS DropdownsCSS Image GalleryCSS Image SpritesCSS Attr SelectorsCSS FormsCSS CountersCSS UnitsCSS InheritanceCSS SpecificityCSS !importantCSS Math FunctionsCSS OptimizationCSS AccessibilityCSS Website Layout

CSS Advanced

CSS Rounded CornersCSS Border ImagesCSS BackgroundsCSS ColorsCSS Color KeywordsCSS GradientsCSS ShadowsCSS Text EffectsCSS Custom FontsCSS 2D TransformsCSS 3D TransformsCSS TransitionsCSS AnimationsCSS TooltipsCSS Image StylingCSS Image ModalCSS Image CenteringCSS Image FiltersCSS Image ShapesCSS object-fitCSS object-positionCSS MaskingCSS ButtonsCSS PaginationCSS Multiple ColumnsCSS User InterfaceCSS VariablesCSS @propertyCSS Box SizingCSS Media QueriesCSS MQ Examples

CSS Flexbox

Flexbox IntroFlex ContainerFlex ItemsFlex Responsive

CSS Grid

Grid IntroGrid ContainerGrid ItemsGrid 12-column LayoutCSS @supports

CSS Responsive

RWD IntroRWD ViewportRWD Grid ViewRWD Media QueriesRWD ImagesRWD VideosRWD FrameworksRWD Templates

CSS SASS

SASS Tutorial

CSS Examples

CSS TemplatesCSS ExamplesCSS EditorCSS SnippetsCSS QuizCSS ExercisesCSS WebsiteCSS SyllabusCSS Study PlanCSS Interview PrepCSS BootcampCSS Certificate

CSS References

CSS ReferenceCSS SelectorsCSS CombinatorsCSS Pseudo-classesCSS Pseudo-elementsCSS At-rulesCSS FunctionsCSS Reference AuralCSS Web Safe FontsCSS AnimatableCSS UnitsCSS PX-EM ConverterCSS ColorsCSS Color ValuesCSS Default ValuesCSS Browser Support

CSSLinks


Text LinkText LinkLink ButtonLink Button

CSS Styling Links

HTML links can be styled with many CSS properties, likecolor,text-decoration,background-color,font-size,font-weight,font-family, etc.).

Example

Style a link with a color, background-color, and a bold font-weight:

a {
  color: hotpink;
  background-color: yellow;
  font-weight: bold;
}
Try it Yourself »

Styling Links Depending on State

In addition, links can be styled differently depending on whatstate they are in.

The four link states are:

  • :link - a normal, unvisited link
  • :visited - a link the user has visited
  • :hover - a link when the user mouses over it
  • :active - a link the moment it is clicked

When setting the style for link states, there are some order rules:

  • :hover must come after :link and :visited
  • :active must come after :hover

Example

Style links according to link state:

/* unvisited link */
a:link {
  color: red;
}

/* visited link */
a:visited {
  color: green;
}

/* mouse over link */
a:hover {
  color: hotpink;
}

/* selected link */
a:active {
 color: blue;
}
Try it Yourself »


CSS Links - Text Decoration

Thetext-decoration property is mostly used to remove underlines from links:

Example

a:link {
  text-decoration: none;
}

a:visited {
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

a:active {
  text-decoration: underline;
}
Try it Yourself »

CSS Links - Background Color

Thebackground-color property can be used to specify a background color for links:

Example

a:link {
  background-color: yellow;
}

a:visited {
  background-color: cyan;
}

a:hover {
  background-color: lightgreen;
}

a:active {
  background-color: hotpink;
Try it Yourself »

CSS Link Buttons

CSS can be used to create HTML link buttons:

Example

Combine several CSS properties to display links as boxes/buttons

a:link, a:visited {
  background-color: #f44336;
  color: white;
  padding: 14px 25px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
}

a:hover, a:active {
  background-color: red;
}
Try it Yourself »

Example

Another example of how to create link boxes/buttons:

a:link, a:visited {
  background-color: white;
  color: black;
  border: 2px solid green;
  padding: 10px 20px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
}

a:hover, a:active {
  background-color: green;
  color: white;
}
Try it Yourself »

More Examples

Example

This example demonstrates how to add other styles to HTML links:

a.one:link {color:red;}
a.one:visited {color:blue;}
a.one:hover {color:orange;}

a.two:link {color:red;}
a.two:visited {color:blue;}
a.two:hover {font-size:150%;}

a.three:link {color:red;}
a.three:visited {color:blue;}
a.three:hover {background:lightgreen;}

a.four:link {color:red;}
a.four:visited {color:blue;}
a.four:hover {font-family:monospace;}

a.five:link {color:red;text-decoration:none;}
a.five:visited {color:blue;text-decoration:none;}
a.five:hover {text-decoration:underline;}
Try it Yourself »

Example

This example demonstrates the different types of cursors (can be useful for links):

<span style="cursor: auto">auto</span><br>
<span style="cursor: crosshair">crosshair</span><br>
<span style="cursor: default">default</span><br>
<span style="cursor: e-resize">e-resize</span><br>
<span style="cursor: help">help</span><br>
<span style="cursor: move">move</span><br>
<span style="cursor: n-resize">n-resize</span><br>
<span style="cursor: ne-resize">ne-resize</span><br>
<span style="cursor: nw-resize">nw-resize</span><br>
<span style="cursor: pointer">pointer</span><br>
<span style="cursor: progress">progress</span><br>
<span style="cursor: s-resize">s-resize</span><br>
<span style="cursor: se-resize">se-resize</span><br>
<span style="cursor: sw-resize">sw-resize</span><br>
<span style="cursor: text">text</span><br>
<span style="cursor: w-resize">w-resize</span><br>
<span style="cursor: wait">wait</span>
Try it Yourself »




×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning.
Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness
of all content. While using W3Schools, you agree to have read and accepted ourterms of use,cookies andprivacy policy.

Copyright 1999-2025 by Refsnes Data. All Rights Reserved.W3Schools is Powered by W3.CSS.


[8]ページ先頭

©2009-2025 Movatter.jp