Explain Codes LogoExplain Codes Logo

Turn off iPhone/Safari input element rounding

web-development
responsive-design
css
input-elements
Nikita BarsukovbyNikita Barsukov·Dec 23, 2024
TLDR

For eradicating Safari's default input rounding on an iPhone, the most effective CSS rule would be -webkit-appearance: none;. Paired with border-radius: 0;, a uniform rectangle shape is guaranteed.

input { -webkit-appearance: none; /* No more iPhone Safari liposuction! */ border-radius: 0; /* Squaring off all edges */ }

Unraveling the CSS magic

Let's chunk down the CSS magic and explore the underpinnings behind it:

Dealing with different input types

iOS may parade various input types, each with unique styling. To get rid of their pesky padding:

input[type="search"] { -webkit-appearance: none; /* A magic wand to vanish predefined styling */ border-radius: 0; /* Everyone's a square now! */ }

Old-school fix for old-school problems

On antiquated iOS versions, -webkit-border-radius was the go-to solution. But make sure to adapt to border-radius to keep up with the current fashion. Retaining standard CSS properties assures longer shelf life.

Test, test, and test some more

Conduct extensive cross-browser and cross-version tests to ensure your inputs remain flawless. Remember the old saying, "Trust but verify"?

Styling input refinements

Every website has its unique style, and your input fields shouldn't toss it to the wind:

Keep up with the styling Joneses

A jarring input field style can ruin the end user experience. Make sure your input fields blend in with your design LinkedIn profile picture.

Prefix properties: Handle with care

Apple could at any moment drop support for -webkit- prefixed properties. Unless you have a "Back to the Future" DeLorean, avoid extensive dependence.

The code cleanup

Clean code is happy code. Follow these tips to avoid shooting yourself in the foot:

  • Use specific selectors: Save the ear for the corn, just like keeping the style for the right input.
  • Validate changes: Make sure Safari isn't the only browser at your party.
  • Think twice before shaking up Select Option styling: <select> elements are sensitive beings.

Two wrongs can make a right

Manifesting the truism "Two negatives make a positive", you might find -webkit-appearance: none and border-radius: 0 working better in tandem:

input { -webkit-appearance: none; /* Say "no" to iOS default */ border-radius: 0; /* All aboard the square train! */ }