Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • CSS Tutorial
  • CSS Exercises
  • CSS Interview Questions
  • CSS Selectors
  • CSS Properties
  • CSS Functions
  • CSS Examples
  • CSS Cheat Sheet
  • CSS Templates
  • CSS Frameworks
  • Bootstrap
  • Tailwind
  • CSS Formatter
Open In App
Next Article:
How to Create Wave Background using CSS?
Next article icon

Create a Galaxy Background using HTML/CSS

Last Updated : 25 Jun, 2022
Comments
Improve
Suggest changes
Like Article
Like
Report

In this article, we will see how to create the galaxy background using the HTML & CSS, along with knowing the basic CSS properties used & will understand it through the example. A galaxy background means a small bunch of circles having different sizes with different shades and a dark background. This task can be accomplished by utilizing the following CSS properties:

  • background-color: This property is used to implement the black-background color to the body element. The background covers the total size of the element with padding and border but excluding margin.
  • border-radius: This property is used to round the corners of the outer border edges of an element. Here, we have used this property to create the circular star-shaped symbol.
  • box-shadow: This property is used to give a shadow-like effect to the frames of an element. The multiple effects can be applied to the element’s frame which is separated by the comma. Here, we have used this property to add the shadow effect to the circular star-shaped symbol.
  • height: This property is used to set the height of the element. Here, we have used this property to add height to the circular star-shaped symbol.
  • width: This property is used to set the width of the element. The width can be assign to the text and images in the form of pixels(px), percentage(%), centimetre(cm) etc. Here, we have used this property to add width to the circular star-shaped symbol.

Approach: In order to create the galaxy background, we will define a <div> element and an image, along with having a class as .gfg that will contain the above required styling properties to utilized them to make the  stars of different sizes with a dark background.

Example: In the below example, we have created a galaxy in the background using the basics of HTML and CSS.

HTML




<!DOCTYPE html>
<html>
  
<head>
    <title>
        Galaxy background using HTML & CSS
    </title>
  
    <style>
        body {
            background-color: black;
        }
  
        .gfg {
            top: 60%;
            left: 40%;
            bottom: 50%;
            height: 12px;
            width: 12px;
            background-color: white;
            border-radius: 80%;
            box-shadow: 34em 54em 3px 4px red, 38vw -4vh 2px 5px lightgreen,
                -20vw -148vh 8px 4px green, -39vw 38vh 4px 10px pink,
                -42vw -11vh 4px 13px green, 12vw 15vh 3px 3px grey,
                42vw 6vh 3px 2px yellow, -8vw 9vh 0px 2px blue,
                34vw -38vh 1px 0px red, -17vw 45vh 3px 1px lightgreen,
                22vw -36vh 3px 10px red, -42vw 1vh 1px 0px yellow,
                42vw -26vh 3px 10px purple, 36vh 5px 10px red;
        }
    </style>
</head>
  
<body>
    <center>
        <img src=
"https://media.geeksforgeeks.org/wp-content/uploads/20210915115837/gfg3.png" 
            alt="GFG image"
            height="150px" />
        <div class="gfg"></div>
    </center>
</body>
  
</html>
 
 

Output:

 



Next Article
How to Create Wave Background using CSS?

A

abhishekpal97854368
Improve
Article Tags :
  • CSS
  • Web Technologies
  • CSS-Properties
  • CSS-Questions
  • HTML-Questions

Similar Reads

  • Create a CSS Fireflies background using HTML/CSS
    In this article, we will see how to create the CSS Fireflies background using HTML & CSS, along with understanding its implementation through the illustration. The CSS fireflies effect can be created by utilizing the CSS animation and we will implement 3 animations to achieve the fireflies effec
    7 min read
  • How to create a skewed background using CSS ?
    A skewed background design enhances a website's visual appeal with dynamic, angled elements. By using CSS transform: skew() along with ::before and ::after pseudo-elements, you can easily create a slanted effect, adding a modern and engaging look to your site's layout. ApproachHTML Structure - Secti
    2 min read
  • How to create texture background using CSS ?
    Introduction: We can use CSS property to texture the background of the web page by using an image editor to cut out a portion of the background. Apply CSS background-repeat property to make the small image fill the area where it is used. CSS provides many styling properties of the background includi
    3 min read
  • How to Create Wave Background using CSS?
    A wave background is a design element having wavy patterns or shapes used to add movement in the web pages. The :before pseudo-element can be used to create a wavy background by applying it to an element and using CSS properties like clip-path to create wave shapes. Using :before pseudo-elementTo cr
    2 min read
  • How to create linear gradient background using CSS ?
    In CSS, we can use the background-color property to set the background color of an element to a specific color. Sometimes we want to add more styling to the element when setting the background color by using the linear-gradient property. CSS linear-gradient property lets you display smooth transitio
    4 min read
  • How to Create Breadcrumbs using HTML and CSS ?
    Create an attractive Breadcrumbs navigation is quite difficult for NON-CSS experts. Without using CSS, the Breadcrumbs navigation will steal your website's gorgeousness. By using only HTML and CSS we can create an attractive Breadcrumbs navigation. In this article, the main focus will be CSS. We wil
    4 min read
  • How to Create Custom Banner Background Using CSS ?
    A Custom Banner Background in CSS refers to a specifically designed or styled background for a webpage banner, often using unique images, colors, gradients, or patterns. It enhances visual appeal and branding by adjusting properties like background-size, and background-position for a tailored look.
    2 min read
  • How to create a Full-Page Background with CSS ?
    To create a full-page background with CSS, set the body's height to `100vh` to cover the viewport, and add a background image using `background-image`. Ensure the image fills the entire viewport without distortion by setting 'background-size: cover'. Optionally, adjust 'background-position' and 'bac
    2 min read
  • Set Background Color using CSS
    Setting the background color in CSS involves using the background-color property to define the color displayed behind the content within an HTML element. This can be achieved through three primary methods: inline CSS, internal CSS, and external CSS. Each method offers different advantages depending
    4 min read
  • How to Create Badges using HTML and CSS ?
    This article will show you how to create a badge using HTML and CSS. Badges are simple and basic components that are used to display an indicator or count a number. This is quite useful for mail count and alerting purposes, among other things. Badges are identical to labels, with the exception that
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences