Skip to content
Related Articles

Related Articles

How to Display the file format of links using CSS ?

View Discussion
Improve Article
Save Article
  • Difficulty Level : Expert
  • Last Updated : 03 Feb, 2021
View Discussion
Improve Article
Save Article

In this article, we will explain the approach to display the file formats on a webpage. Many times while browsing, we need to download a document file but in PDF format, however, a problem might occur that multiple links of downloading the file are there, but each link contains different file formats. One may contain a document file and another may contain a PDF file. We cannot easily know which one is which just by looking at the links.

Therefore, to solve this problem, we can disclose file formats of links in our webpage just using some CSS styling. It is done by targeting the file type of the links in the page and appending an icon image using the ::after selector and specifying the content property with the path of the icon. It will automatically insert the icon images on every suitable link it finds on the page that matches the file extension. 


[href$=" .file_extention "]::after {
  content: " " url( path_of_icon );

Example: This example uses ::after selector to display the file format image after the text.


<!DOCTYPE html>
        How to Display file format
        of links using CSS?
    <link rel="stylesheet" type="text/css"
    <style type="text/css">
        a {
            font-family: "Font Awesome 5 Free";
            text-decoration: none;
            font-size: 24px;
            color: black;
        [href$=".pdf"]::after {
            content: '  \f1c1';
            color: red;
        [href$=".docx"]::after {
            content: '  \f1c2';
            color: green;
<body style="text-align: center;">
    <h1 style="color: green;">
    <h3>Display file format of links using CSS</h3>
    <a href="GeeksforGeeks.pdf">PDF File</a>
    <a href="GeeksforGeeks.docx">Word File</a>


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!