Close Menu
Trendswave MediaTrendswave Media
  • Home
  • About Us
    • Contact Us
  • Services
  • Influencer Marketing
  • Marketing
  • SEO
  • Social Media
  • Web Design
  • Shop

Subscribe to Updates

Get the latest creative news from Trendswave about Marketing, SEO & Web Design.

Please enable JavaScript in your browser to complete this form.
Loading
What's Hot

Driving Qualified Leads With LinkedIn Content: A Proven Formula

October 3, 2025

Google Ads copywriting with AI: Getting the prompt right

October 3, 2025

A Practical Guide To Building With Clarity (Part 2) — Smashing Magazine

October 3, 2025
Facebook X (Twitter) Instagram
Trendswave MediaTrendswave Media
  • Home
  • About Us
    • Contact Us
  • Services
  • Influencer Marketing
  • Marketing
  • SEO
  • Social Media
  • Web Design
  • Shop
Trendswave MediaTrendswave Media
Home»Web Design»Make your own URL shortener in JavaScript
Web Design

Make your own URL shortener in JavaScript

adminBy adminDecember 19, 2024No Comments9 Mins Read
Facebook Twitter Pinterest LinkedIn Tumblr WhatsApp VKontakte Email
Make your own URL shortener in JavaScript
Share
Facebook Twitter LinkedIn Pinterest Email


What is a URL Shortener?

A URL shortener is a tool that converts Long URLs into shorter, more manageable links. Once the URL has been shortened, it redirects users to the original URL. 

Short URLs are easier to share on social media, emails, or any other digital platform. Additionally, many URL shorteners offer advanced features such as tracking and analytics that can be useful in providing insights into user engagement.

In this tutorial, we will cover how to create your very own URL shortener tool using JavaScript!

By the end of this tutorial, we will have something like this:

Let’s get started!

Create UI with HTML and CSS

We will be using HTML and CSS to build a simple user interface, featuring the following elements:

  • A form element with a and a button for submission. 
  • A element to display the results and a tag to copy the shortened URL.
  • A   element for displaying any error messages
  • A   element to display a copied message when the URL is copied.

Add this code in the body of the HTML file.

1

class="container">

2
    URL Shortener
3
    
4
         type="url" id="url" placeholder="Enter your long URL" required>
5
        
6
    
7
    

id="result">

8
        Shortened URL:  target="_blank" id="shortened-url">
9
             id="icon" class="fa-solid fa-copy">
10
        
11
    
12
    

id="copy">Copied!

13
    

id="error">

14

Styling with CSS

Let’s rifle through some styles to get things looking the way we want.

To style the page, let’s start by setting the body to use display: flex; this will ensure everything is centered horizontally and vertically.

We’ll also add a background color.

1
body {
2
    display: flex;
3
    justify-content: center;
4
    align-items: center;
5
    height: 100vh;
6
    background-color: #f1f1f1;
7
    font-family: Arial, sans-serif;
8
}

Now let’s add these styles to the container element.

1
.container {
2
    width: 400px;
3
    background-color: #fff;
4
    border-radius: 5px;
5
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
6
    padding: 20px;
7
    text-align: center;
8
}

To ensure the elements in the form ( and



Source link

JavaScript shortener URL
Share. Facebook Twitter Pinterest LinkedIn Tumblr WhatsApp Email
Previous ArticleDaily Search Forum Recap: December 17, 2024
Next Article Tested: Is WordPress Good For SEO in 2024?
admin
  • Website

Related Posts

A Practical Guide To Building With Clarity (Part 2) — Smashing Magazine

October 3, 2025

Fresh Resources for Web Designers and Developers (September 2025)

October 2, 2025

Shades Of October (2025 Wallpapers Edition) — Smashing Magazine

October 1, 2025

Principles And Implementation (Part 1) — Smashing Magazine

September 29, 2025
Leave A Reply Cancel Reply

  • Facebook
  • Twitter
  • Pinterest
  • Instagram
  • YouTube
  • Vimeo
Don't Miss
Marketing

Driving Qualified Leads With LinkedIn Content: A Proven Formula

By adminOctober 3, 20250

Are you struggling to generate qualified leads from your LinkedIn content? Wondering how to transform…

Google Ads copywriting with AI: Getting the prompt right

October 3, 2025

A Practical Guide To Building With Clarity (Part 2) — Smashing Magazine

October 3, 2025

Meta unveils Business AI and new generative tools

October 2, 2025

Subscribe to Updates

Get the latest creative news from Trendswave about Marketing, SEO & Web Design.

Please enable JavaScript in your browser to complete this form.
Loading
About Us

Trendswave is an Influencer Marketing Agency with access to one of the largest influencer networks in the Poland, connecting brands and agencies to only the best influencers and social media thought leaders.

Our Picks

Driving Qualified Leads With LinkedIn Content: A Proven Formula

October 3, 2025

Google Ads copywriting with AI: Getting the prompt right

October 3, 2025
Quicklinks
  • Influencer Marketing
  • Marketing
  • SEO
  • Social Media
  • Web Design
  • About Us
  • Contact Us
  • Disclaimer
  • Privacy Policy
  • Terms and Conditions
© 2025 Trendswave.All Rights Reserved

Type above and press Enter to search. Press Esc to cancel.