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

40+ Best Branding Identity Mockup Templates — Speckyboy

October 7, 2026

Google Updates Crawl Rate Documentation Adds Retry-After HTTP & More

October 7, 2026

How Mugsy Built a Creator Marketing Strategy Around Stretch Denim

October 7, 2026
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

40+ Best Branding Identity Mockup Templates — Speckyboy

October 7, 2026

A Practical Guide To Naming Things — Smashing Magazine

October 6, 2026

Should Your Agency Charge Less for AI-Assisted Solutions? — Speckyboy

October 4, 2026

Under Autumn’s Spell (October 2026 Wallpapers Edition) — Smashing Magazine

October 1, 2026
Leave A Reply Cancel Reply

  • Facebook
  • Twitter
  • Pinterest
  • Instagram
  • YouTube
  • Vimeo
Don't Miss
Web Design

40+ Best Branding Identity Mockup Templates — Speckyboy

By adminOctober 7, 20260

Branding isn’t just what you do. It’s also how you present yourself. So when you’re…

Google Updates Crawl Rate Documentation Adds Retry-After HTTP & More

October 7, 2026

How Mugsy Built a Creator Marketing Strategy Around Stretch Denim

October 7, 2026

Barry Schwartz’s 50,000 Stories On Search

October 7, 2026

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

40+ Best Branding Identity Mockup Templates — Speckyboy

October 7, 2026

Google Updates Crawl Rate Documentation Adds Retry-After HTTP & More

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

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